use of org.bouncycastle.operator.bc.BcECContentVerifierProviderBuilder in project xipki by xipki.
the class CmpCaClient method getContentVerifierProvider.
// method verifyProtection
public static ContentVerifierProvider getContentVerifierProvider(PublicKey publicKey) throws InvalidKeyException {
SdkUtil.requireNonNull("publicKey", publicKey);
String keyAlg = publicKey.getAlgorithm().toUpperCase();
DigestAlgorithmIdentifierFinder digAlgFinder = new DefaultDigestAlgorithmIdentifierFinder();
BcContentVerifierProviderBuilder builder;
if ("RSA".equals(keyAlg)) {
builder = new BcRSAContentVerifierProviderBuilder(digAlgFinder);
} else if ("DSA".equals(keyAlg)) {
builder = new BcDSAContentVerifierProviderBuilder(digAlgFinder);
} else if ("EC".equals(keyAlg) || "ECDSA".equals(keyAlg)) {
builder = new BcECContentVerifierProviderBuilder(digAlgFinder);
} else {
throw new InvalidKeyException("unknown key algorithm of the public key " + keyAlg);
}
AsymmetricKeyParameter keyParam;
if (publicKey instanceof RSAPublicKey) {
RSAPublicKey rsaKey = (RSAPublicKey) publicKey;
keyParam = new RSAKeyParameters(false, rsaKey.getModulus(), rsaKey.getPublicExponent());
} else if (publicKey instanceof ECPublicKey) {
keyParam = ECUtil.generatePublicKeyParameter(publicKey);
} else if (publicKey instanceof DSAPublicKey) {
keyParam = DSAUtil.generatePublicKeyParameter(publicKey);
} else {
throw new InvalidKeyException("unknown key " + publicKey.getClass().getName());
}
try {
return builder.build(keyParam);
} catch (OperatorCreationException ex) {
throw new InvalidKeyException("could not build ContentVerifierProvider: " + ex.getMessage(), ex);
}
}
use of org.bouncycastle.operator.bc.BcECContentVerifierProviderBuilder in project xipki by xipki.
the class CaEmulator method getContentVerifierProvider.
public ContentVerifierProvider getContentVerifierProvider(PublicKey publicKey) throws InvalidKeyException {
ScepUtil.requireNonNull("publicKey", publicKey);
String keyAlg = publicKey.getAlgorithm().toUpperCase();
if ("EC".equals(keyAlg)) {
keyAlg = "ECDSA";
}
BcContentVerifierProviderBuilder builder = VERIFIER_PROVIDER_BUILDER.get(keyAlg);
if (builder == null) {
if ("RSA".equals(keyAlg)) {
builder = new BcRSAContentVerifierProviderBuilder(DFLT_DIGESTALG_IDENTIFIER_FINDER);
} else if ("DSA".equals(keyAlg)) {
builder = new BcDSAContentVerifierProviderBuilder(DFLT_DIGESTALG_IDENTIFIER_FINDER);
} else if ("ECDSA".equals(keyAlg)) {
builder = new BcECContentVerifierProviderBuilder(DFLT_DIGESTALG_IDENTIFIER_FINDER);
} else {
throw new InvalidKeyException("unknown key algorithm of the public key " + keyAlg);
}
VERIFIER_PROVIDER_BUILDER.put(keyAlg, builder);
}
AsymmetricKeyParameter keyParam = generatePublicKeyParameter(publicKey);
try {
return builder.build(keyParam);
} catch (OperatorCreationException ex) {
throw new InvalidKeyException("could not build ContentVerifierProvider: " + ex.getMessage(), ex);
}
}
Aggregations