Example usage for org.bouncycastle.asn1.x509 AlgorithmIdentifier getEncoded

List of usage examples for org.bouncycastle.asn1.x509 AlgorithmIdentifier getEncoded

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.x509 AlgorithmIdentifier getEncoded.

Prototype

public byte[] getEncoded() throws IOException 

Source Link

Document

Return the default BER or DER encoding for this object.

Usage

From source file:org.xwiki.crypto.password.internal.DefaultPrivateKeyPasswordBasedEncryptor.java

License:Open Source License

private PasswordBasedCipher getPBECipher(byte[] password, AlgorithmIdentifier algId) throws IOException {
    PasswordBasedCipherFactory factory = getPBEFactory(algId.getAlgorithm().getId());

    // Optimization
    if (factory instanceof AbstractBcPBCipherFactory) {
        return ((AbstractBcPBCipherFactory) factory).getInstance(false, password, algId);
    }/*w  w w.ja v  a 2 s  .c  o  m*/

    return factory.getInstance(false, password, algId.getEncoded());
}

From source file:org.xwiki.crypto.signer.internal.DefaultBcContentVerifierProviderBuilder.java

License:Open Source License

private ContentVerifier getInstance(CipherParameters parameters, final AlgorithmIdentifier algId) {
    SignerFactory factory = getFactory(algId.getAlgorithm().getId());

    if (factory instanceof BcSignerFactory) {
        return (ContentVerifier) ((BcSignerFactory) factory).getInstance(false, parameters, algId);
    }//from w  w  w .j a v a2  s  .  c o  m

    final org.xwiki.crypto.signer.Signer signer;
    try {
        signer = factory.getInstance(false, parameters, algId.getEncoded());
    } catch (IOException e) {
        // Unlikely
        throw new IllegalArgumentException("Unable to encode algorithm identifier.");
    }

    return new ContentVerifier() {
        @Override
        public AlgorithmIdentifier getAlgorithmIdentifier() {
            return algId;
        }

        @Override
        public OutputStream getOutputStream() {
            return signer.getOutputStream();
        }

        @Override
        public boolean verify(byte[] bytes) {
            return DefaultBcContentVerifierProviderBuilder.verify(signer, bytes);
        }
    };
}