Search in sources :

Example 1 with BasePublicEncryptionKey

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

the class BcITSPublicEncryptionKey method getKey.

public AsymmetricKeyParameter getKey() {
    X9ECParameters params;
    BasePublicEncryptionKey baseKey = encryptionKey.getBasePublicEncryptionKey();
    ASN1ObjectIdentifier curveID;
    switch(baseKey.getChoice()) {
        case BasePublicEncryptionKey.eciesNistP256:
            curveID = SECObjectIdentifiers.secp256r1;
            params = NISTNamedCurves.getByOID(SECObjectIdentifiers.secp256r1);
            break;
        case BasePublicEncryptionKey.eciesBrainpoolP256r1:
            curveID = TeleTrusTObjectIdentifiers.brainpoolP256r1;
            params = TeleTrusTNamedCurves.getByOID(TeleTrusTObjectIdentifiers.brainpoolP256r1);
            break;
        default:
            throw new IllegalStateException("unknown key type");
    }
    ECCurve curve = params.getCurve();
    ASN1Encodable pviCurvePoint = encryptionKey.getBasePublicEncryptionKey().getValue();
    final EccCurvePoint itsPoint;
    if (pviCurvePoint instanceof EccCurvePoint) {
        itsPoint = (EccCurvePoint) baseKey.getValue();
    } else {
        throw new IllegalStateException("extension to public verification key not supported");
    }
    byte[] key;
    if (itsPoint instanceof EccP256CurvePoint) {
        key = itsPoint.getEncodedPoint();
    } else if (itsPoint instanceof EccP384CurvePoint) {
        key = itsPoint.getEncodedPoint();
    } else {
        throw new IllegalStateException("unknown key type");
    }
    ECPoint point = curve.decodePoint(key).normalize();
    return new ECPublicKeyParameters(point, new ECNamedDomainParameters(curveID, params));
}
Also used : X9ECParameters(com.github.zhenwei.core.asn1.x9.X9ECParameters) EccCurvePoint(com.github.zhenwei.pkix.util.oer.its.EccCurvePoint) ECNamedDomainParameters(com.github.zhenwei.core.crypto.params.ECNamedDomainParameters) ECPoint(com.github.zhenwei.core.math.ec.ECPoint) ECPublicKeyParameters(com.github.zhenwei.core.crypto.params.ECPublicKeyParameters) BasePublicEncryptionKey(com.github.zhenwei.pkix.util.oer.its.BasePublicEncryptionKey) ECCurve(com.github.zhenwei.core.math.ec.ECCurve) EccP256CurvePoint(com.github.zhenwei.pkix.util.oer.its.EccP256CurvePoint) EccP384CurvePoint(com.github.zhenwei.pkix.util.oer.its.EccP384CurvePoint) ASN1Encodable(com.github.zhenwei.core.asn1.ASN1Encodable) ASN1ObjectIdentifier(com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)

Example 2 with BasePublicEncryptionKey

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

the class JceITSPublicEncryptionKey method getKey.

public PublicKey getKey() {
    BasePublicEncryptionKey baseKey = encryptionKey.getBasePublicEncryptionKey();
    X9ECParameters params;
    switch(baseKey.getChoice()) {
        case BasePublicEncryptionKey.eciesNistP256:
            params = NISTNamedCurves.getByOID(SECObjectIdentifiers.secp256r1);
            break;
        case BasePublicEncryptionKey.eciesBrainpoolP256r1:
            params = TeleTrusTNamedCurves.getByOID(TeleTrusTObjectIdentifiers.brainpoolP256r1);
            break;
        default:
            throw new IllegalStateException("unknown key type");
    }
    ASN1Encodable pviCurvePoint = encryptionKey.getBasePublicEncryptionKey().getValue();
    final EccCurvePoint itsPoint;
    if (pviCurvePoint instanceof EccCurvePoint) {
        itsPoint = (EccCurvePoint) baseKey.getValue();
    } else {
        throw new IllegalStateException("extension to public verification key not supported");
    }
    ECCurve curve = params.getCurve();
    byte[] key;
    if (itsPoint instanceof EccP256CurvePoint) {
        key = itsPoint.getEncodedPoint();
    } else if (itsPoint instanceof EccP384CurvePoint) {
        key = itsPoint.getEncodedPoint();
    } else {
        throw new IllegalStateException("unknown key type");
    }
    ECPoint point = curve.decodePoint(key).normalize();
    try {
        KeyFactory keyFactory = helper.createKeyFactory("EC");
        ECParameterSpec spec = EC5Util.convertToSpec(params);
        java.security.spec.ECPoint jPoint = EC5Util.convertPoint(point);
        return keyFactory.generatePublic(new ECPublicKeySpec(jPoint, spec));
    } catch (Exception e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
Also used : X9ECParameters(com.github.zhenwei.core.asn1.x9.X9ECParameters) EccCurvePoint(com.github.zhenwei.pkix.util.oer.its.EccCurvePoint) ECPoint(com.github.zhenwei.core.math.ec.ECPoint) ECPublicKeySpec(java.security.spec.ECPublicKeySpec) ECParameterSpec(java.security.spec.ECParameterSpec) BasePublicEncryptionKey(com.github.zhenwei.pkix.util.oer.its.BasePublicEncryptionKey) ECCurve(com.github.zhenwei.core.math.ec.ECCurve) EccP256CurvePoint(com.github.zhenwei.pkix.util.oer.its.EccP256CurvePoint) EccP384CurvePoint(com.github.zhenwei.pkix.util.oer.its.EccP384CurvePoint) ASN1Encodable(com.github.zhenwei.core.asn1.ASN1Encodable) KeyFactory(java.security.KeyFactory)

Aggregations

ASN1Encodable (com.github.zhenwei.core.asn1.ASN1Encodable)2 X9ECParameters (com.github.zhenwei.core.asn1.x9.X9ECParameters)2 ECCurve (com.github.zhenwei.core.math.ec.ECCurve)2 ECPoint (com.github.zhenwei.core.math.ec.ECPoint)2 BasePublicEncryptionKey (com.github.zhenwei.pkix.util.oer.its.BasePublicEncryptionKey)2 EccCurvePoint (com.github.zhenwei.pkix.util.oer.its.EccCurvePoint)2 EccP256CurvePoint (com.github.zhenwei.pkix.util.oer.its.EccP256CurvePoint)2 EccP384CurvePoint (com.github.zhenwei.pkix.util.oer.its.EccP384CurvePoint)2 ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)1 ECNamedDomainParameters (com.github.zhenwei.core.crypto.params.ECNamedDomainParameters)1 ECPublicKeyParameters (com.github.zhenwei.core.crypto.params.ECPublicKeyParameters)1 KeyFactory (java.security.KeyFactory)1 ECParameterSpec (java.security.spec.ECParameterSpec)1 ECPublicKeySpec (java.security.spec.ECPublicKeySpec)1