Search in sources :

Example 1 with XiRSAContentVerifierProviderBuilder

use of org.xipki.security.bc.XiRSAContentVerifierProviderBuilder in project xipki by xipki.

the class SecurityFactoryImpl method getContentVerifierProvider.

@Override
public ContentVerifierProvider getContentVerifierProvider(PublicKey publicKey) throws InvalidKeyException {
    ParamUtil.requireNonNull("publicKey", publicKey);
    String keyAlg = publicKey.getAlgorithm().toUpperCase();
    BcContentVerifierProviderBuilder builder = VERIFIER_PROVIDER_BUILDER.get(keyAlg);
    if (builder == null) {
        if ("RSA".equals(keyAlg)) {
            builder = new XiRSAContentVerifierProviderBuilder(DIGESTALG_IDENTIFIER_FINDER);
        } else if ("DSA".equals(keyAlg)) {
            builder = new BcDSAContentVerifierProviderBuilder(DIGESTALG_IDENTIFIER_FINDER);
        } else if ("EC".equals(keyAlg) || "ECDSA".equals(keyAlg)) {
            builder = new XiECContentVerifierProviderBuilder(DIGESTALG_IDENTIFIER_FINDER);
        } else {
            throw new InvalidKeyException("unknown key algorithm of the public key " + keyAlg);
        }
        VERIFIER_PROVIDER_BUILDER.put(keyAlg, builder);
    }
    AsymmetricKeyParameter keyParam = KeyUtil.generatePublicKeyParameter(publicKey);
    try {
        return builder.build(keyParam);
    } catch (OperatorCreationException ex) {
        throw new InvalidKeyException("could not build ContentVerifierProvider: " + ex.getMessage(), ex);
    }
}
Also used : XiRSAContentVerifierProviderBuilder(org.xipki.security.bc.XiRSAContentVerifierProviderBuilder) BcContentVerifierProviderBuilder(org.bouncycastle.operator.bc.BcContentVerifierProviderBuilder) AsymmetricKeyParameter(org.bouncycastle.crypto.params.AsymmetricKeyParameter) XiECContentVerifierProviderBuilder(org.xipki.security.bc.XiECContentVerifierProviderBuilder) BcDSAContentVerifierProviderBuilder(org.bouncycastle.operator.bc.BcDSAContentVerifierProviderBuilder) InvalidKeyException(java.security.InvalidKeyException) OperatorCreationException(org.bouncycastle.operator.OperatorCreationException)

Aggregations

InvalidKeyException (java.security.InvalidKeyException)1 AsymmetricKeyParameter (org.bouncycastle.crypto.params.AsymmetricKeyParameter)1 OperatorCreationException (org.bouncycastle.operator.OperatorCreationException)1 BcContentVerifierProviderBuilder (org.bouncycastle.operator.bc.BcContentVerifierProviderBuilder)1 BcDSAContentVerifierProviderBuilder (org.bouncycastle.operator.bc.BcDSAContentVerifierProviderBuilder)1 XiECContentVerifierProviderBuilder (org.xipki.security.bc.XiECContentVerifierProviderBuilder)1 XiRSAContentVerifierProviderBuilder (org.xipki.security.bc.XiRSAContentVerifierProviderBuilder)1