Search in sources :

Example 1 with EccP256CurvePoint

use of com.github.zhenwei.pkix.util.oer.its.EccP256CurvePoint 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 EccP256CurvePoint

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

the class BcITSPublicVerificationKey method getKey.

public AsymmetricKeyParameter getKey() {
    X9ECParameters params;
    ASN1ObjectIdentifier curveID;
    switch(verificationKey.getChoice()) {
        case PublicVerificationKey.ecdsaNistP256:
            curveID = SECObjectIdentifiers.secp256r1;
            params = NISTNamedCurves.getByOID(SECObjectIdentifiers.secp256r1);
            break;
        case PublicVerificationKey.ecdsaBrainpoolP256r1:
            curveID = TeleTrusTObjectIdentifiers.brainpoolP256r1;
            params = TeleTrusTNamedCurves.getByOID(TeleTrusTObjectIdentifiers.brainpoolP256r1);
            break;
        case PublicVerificationKey.ecdsaBrainpoolP384r1:
            curveID = TeleTrusTObjectIdentifiers.brainpoolP384r1;
            params = TeleTrusTNamedCurves.getByOID(TeleTrusTObjectIdentifiers.brainpoolP384r1);
            break;
        default:
            throw new IllegalStateException("unknown key type");
    }
    ECCurve curve = params.getCurve();
    ASN1Encodable pviCurvePoint = verificationKey.getCurvePoint();
    final EccCurvePoint itsPoint;
    if (pviCurvePoint instanceof EccCurvePoint) {
        itsPoint = (EccCurvePoint) verificationKey.getCurvePoint();
    } 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) ECCurve(com.github.zhenwei.core.math.ec.ECCurve) EccCurvePoint(com.github.zhenwei.pkix.util.oer.its.EccCurvePoint) ECNamedDomainParameters(com.github.zhenwei.core.crypto.params.ECNamedDomainParameters) 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) ECPoint(com.github.zhenwei.core.math.ec.ECPoint) ECPublicKeyParameters(com.github.zhenwei.core.crypto.params.ECPublicKeyParameters) ASN1ObjectIdentifier(com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)

Example 3 with EccP256CurvePoint

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

the class JcaITSPublicVerificationKey method getKey.

public PublicKey getKey() {
    X9ECParameters params;
    switch(verificationKey.getChoice()) {
        case PublicVerificationKey.ecdsaNistP256:
            params = NISTNamedCurves.getByOID(SECObjectIdentifiers.secp256r1);
            break;
        case PublicVerificationKey.ecdsaBrainpoolP256r1:
            params = TeleTrusTNamedCurves.getByOID(TeleTrusTObjectIdentifiers.brainpoolP256r1);
            break;
        case PublicVerificationKey.ecdsaBrainpoolP384r1:
            params = TeleTrusTNamedCurves.getByOID(TeleTrusTObjectIdentifiers.brainpoolP384r1);
            break;
        default:
            throw new IllegalStateException("unknown key type");
    }
    ECCurve curve = params.getCurve();
    ASN1Encodable pviCurvePoint = verificationKey.getCurvePoint();
    final EccCurvePoint itsPoint;
    if (pviCurvePoint instanceof EccCurvePoint) {
        itsPoint = (EccCurvePoint) verificationKey.getCurvePoint();
    } 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();
    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) 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)

Example 4 with EccP256CurvePoint

use of com.github.zhenwei.pkix.util.oer.its.EccP256CurvePoint 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)

Example 5 with EccP256CurvePoint

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

the class ITSImplicitCertificateBuilder method build.

public ITSCertificate build(CertificateId certificateId, BigInteger x, BigInteger y, PublicEncryptionKey publicEncryptionKey) {
    EccP256CurvePoint reconstructionValue = EccP256CurvePoint.builder().createUncompressedP256(x, y);
    ToBeSignedCertificate.Builder tbsBldr = new ToBeSignedCertificate.Builder(tbsCertificateBuilder);
    tbsBldr.setCertificateId(certificateId);
    if (publicEncryptionKey != null) {
        tbsBldr.setEncryptionKey(publicEncryptionKey);
    }
    tbsBldr.setVerificationKeyIndicator(VerificationKeyIndicator.builder().reconstructionValue(reconstructionValue).createVerificationKeyIndicator());
    CertificateBase.Builder baseBldr = new CertificateBase.Builder();
    baseBldr.setVersion(version);
    baseBldr.setType(CertificateType.Implicit);
    baseBldr.setIssuer(issuerIdentifier);
    baseBldr.setToBeSignedCertificate(tbsBldr.createToBeSignedCertificate());
    Certificate.Builder bldr = new Certificate.Builder();
    bldr.setCertificateBase(baseBldr.createCertificateBase());
    return new ITSCertificate(bldr.createCertificate());
}
Also used : CertificateBase(com.github.zhenwei.pkix.util.oer.its.CertificateBase) EccP256CurvePoint(com.github.zhenwei.pkix.util.oer.its.EccP256CurvePoint) ToBeSignedCertificate(com.github.zhenwei.pkix.util.oer.its.ToBeSignedCertificate) Certificate(com.github.zhenwei.pkix.util.oer.its.Certificate) ToBeSignedCertificate(com.github.zhenwei.pkix.util.oer.its.ToBeSignedCertificate)

Aggregations

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