Search in sources :

Example 1 with SM2Signer

use of org.bouncycastle.crypto.signers.SM2Signer in project xipki by xipki.

the class XiECContentVerifierProviderBuilder method createSigner.

protected Signer createSigner(AlgorithmIdentifier sigAlgId) throws OperatorCreationException {
    boolean plainDsa = AlgorithmUtil.isPlainECDSASigAlg(sigAlgId);
    if (plainDsa) {
        AlgorithmIdentifier digAlg = digestAlgorithmFinder.find(sigAlgId);
        Digest dig = digestProvider.get(digAlg);
        return new DSAPlainDigestSigner(new ECDSASigner(), dig);
    }
    boolean sm2 = AlgorithmUtil.isSM2SigAlg(sigAlgId);
    if (sm2) {
        AlgorithmIdentifier digAlg = digestAlgorithmFinder.find(sigAlgId);
        if (GMObjectIdentifiers.sm3.equals(digAlg.getAlgorithm())) {
            return new SM2Signer();
        } else {
            throw new OperatorCreationException("cannot create SM2 signer for hash algorithm " + digAlg.getAlgorithm().getId());
        }
    }
    return super.createSigner(sigAlgId);
}
Also used : Digest(org.bouncycastle.crypto.Digest) ECDSASigner(org.bouncycastle.crypto.signers.ECDSASigner) OperatorCreationException(org.bouncycastle.operator.OperatorCreationException) SM2Signer(org.bouncycastle.crypto.signers.SM2Signer) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier) DSAPlainDigestSigner(org.xipki.security.pkcs12.DSAPlainDigestSigner)

Aggregations

AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)1 Digest (org.bouncycastle.crypto.Digest)1 ECDSASigner (org.bouncycastle.crypto.signers.ECDSASigner)1 SM2Signer (org.bouncycastle.crypto.signers.SM2Signer)1 OperatorCreationException (org.bouncycastle.operator.OperatorCreationException)1 DSAPlainDigestSigner (org.xipki.security.pkcs12.DSAPlainDigestSigner)1