Example usage for org.bouncycastle.operator ContentSigner ContentSigner

List of usage examples for org.bouncycastle.operator ContentSigner ContentSigner

Introduction

In this page you can find the example usage for org.bouncycastle.operator ContentSigner ContentSigner.

Prototype

ContentSigner

Source Link

Usage

From source file:org.tdmx.client.crypto.algorithm.SignatureAlgorithm.java

License:Open Source License

public static ContentSigner getContentSigner(final PrivateKey privateKey, final SignatureAlgorithm alg) {
    return new ContentSigner() {

        private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        @Override//from w  w  w .j a  va  2  s.  com
        public byte[] getSignature() {

            try {
                Signature signer = alg.getSignature(privateKey);
                signer.update(outputStream.toByteArray());
                return signer.sign();
            } catch (CryptoException e) {
                return null;
            } catch (SignatureException e) {
                return null;
            }
        }

        @Override
        public OutputStream getOutputStream() {
            return outputStream;
        }

        @Override
        public AlgorithmIdentifier getAlgorithmIdentifier() {
            return new AlgorithmIdentifier(alg.getAsn1oid());
        }
    };

}