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));
}
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);
}
}
Aggregations