Search in sources :

Example 1 with PublicEncryptionKey

use of com.github.zhenwei.pkix.util.oer.its.PublicEncryptionKey in project LinLong-Java by zhenwei1108.

the class BcITSPublicEncryptionKey method fromKeyParameters.

static PublicEncryptionKey fromKeyParameters(ECPublicKeyParameters pubKey) {
    ASN1ObjectIdentifier curveID = ((ECNamedDomainParameters) pubKey.getParameters()).getName();
    ECPoint q = pubKey.getQ();
    if (curveID.equals(SECObjectIdentifiers.secp256r1)) {
        return new PublicEncryptionKey(SymmAlgorithm.aes128Ccm, new BasePublicEncryptionKey.Builder().setChoice(BasePublicEncryptionKey.eciesNistP256).setValue(EccP256CurvePoint.builder().createUncompressedP256(q.getAffineXCoord().toBigInteger(), q.getAffineYCoord().toBigInteger())).createBasePublicEncryptionKey());
    } else if (curveID.equals(TeleTrusTObjectIdentifiers.brainpoolP256r1)) {
        return new PublicEncryptionKey(SymmAlgorithm.aes128Ccm, new BasePublicEncryptionKey.Builder().setChoice(BasePublicEncryptionKey.eciesBrainpoolP256r1).setValue(EccP256CurvePoint.builder().createUncompressedP256(q.getAffineXCoord().toBigInteger(), q.getAffineYCoord().toBigInteger())).createBasePublicEncryptionKey());
    } else {
        throw new IllegalArgumentException("unknown curve in public encryption key");
    }
}
Also used : BasePublicEncryptionKey(com.github.zhenwei.pkix.util.oer.its.BasePublicEncryptionKey) PublicEncryptionKey(com.github.zhenwei.pkix.util.oer.its.PublicEncryptionKey) ITSPublicEncryptionKey(com.github.zhenwei.pkix.its.ITSPublicEncryptionKey) ECNamedDomainParameters(com.github.zhenwei.core.crypto.params.ECNamedDomainParameters) BasePublicEncryptionKey(com.github.zhenwei.pkix.util.oer.its.BasePublicEncryptionKey) ECPoint(com.github.zhenwei.core.math.ec.ECPoint) ASN1ObjectIdentifier(com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)

Example 2 with PublicEncryptionKey

use of com.github.zhenwei.pkix.util.oer.its.PublicEncryptionKey in project LinLong-Java by zhenwei1108.

the class JceITSPublicEncryptionKey method fromPublicKey.

static PublicEncryptionKey fromPublicKey(PublicKey key) {
    if (!(key instanceof ECPublicKey)) {
        throw new IllegalArgumentException("must be ECPublicKey instance");
    }
    ECPublicKey pKey = (ECPublicKey) key;
    ASN1ObjectIdentifier curveID = ASN1ObjectIdentifier.getInstance(SubjectPublicKeyInfo.getInstance(key.getEncoded()).getAlgorithm().getParameters());
    if (curveID.equals(SECObjectIdentifiers.secp256r1)) {
        return new PublicEncryptionKey(SymmAlgorithm.aes128Ccm, new BasePublicEncryptionKey.Builder().setChoice(BasePublicEncryptionKey.eciesNistP256).setValue(EccP256CurvePoint.builder().createUncompressedP256(pKey.getW().getAffineX(), pKey.getW().getAffineY())).createBasePublicEncryptionKey());
    } else if (curveID.equals(TeleTrusTObjectIdentifiers.brainpoolP256r1)) {
        return new PublicEncryptionKey(SymmAlgorithm.aes128Ccm, new BasePublicEncryptionKey.Builder().setChoice(BasePublicEncryptionKey.eciesBrainpoolP256r1).setValue(EccP256CurvePoint.builder().createUncompressedP256(pKey.getW().getAffineX(), pKey.getW().getAffineY())).createBasePublicEncryptionKey());
    } else {
        throw new IllegalArgumentException("unknown curve in public encryption key");
    }
}
Also used : ECPublicKey(java.security.interfaces.ECPublicKey) PublicEncryptionKey(com.github.zhenwei.pkix.util.oer.its.PublicEncryptionKey) BasePublicEncryptionKey(com.github.zhenwei.pkix.util.oer.its.BasePublicEncryptionKey) ITSPublicEncryptionKey(com.github.zhenwei.pkix.its.ITSPublicEncryptionKey) BasePublicEncryptionKey(com.github.zhenwei.pkix.util.oer.its.BasePublicEncryptionKey) ASN1ObjectIdentifier(com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)

Aggregations

ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)2 ITSPublicEncryptionKey (com.github.zhenwei.pkix.its.ITSPublicEncryptionKey)2 BasePublicEncryptionKey (com.github.zhenwei.pkix.util.oer.its.BasePublicEncryptionKey)2 PublicEncryptionKey (com.github.zhenwei.pkix.util.oer.its.PublicEncryptionKey)2 ECNamedDomainParameters (com.github.zhenwei.core.crypto.params.ECNamedDomainParameters)1 ECPoint (com.github.zhenwei.core.math.ec.ECPoint)1 ECPublicKey (java.security.interfaces.ECPublicKey)1