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