Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.google.code.springcryptoutils.core.signature;
 
The default implementation for providing digital signatures.

Author(s):
Mirko Caserta (mirko.caserta@gmail.com)
public class SignerImpl implements Signer {
    private PrivateKey privateKey;
    private String algorithm = "SHA1withRSA";

    
The private key for signing the message.

Parameters:
privateKey the private key
    public void setPrivateKey(PrivateKey privateKey) {
        this. = privateKey;
    }

    
The signature algorithm. The default is SHA1withRSA.

Parameters:
algorithm the signature algorithm
    public void setAlgorithm(String algorithm) {
        this. = algorithm;
    }

    
Signs a message.

Parameters:
message the message to sign
Returns:
the signature
    public byte[] sign(byte[] message) {
        try {
            // this way signatureInstance should be thread safe
            final Signature signatureInstance = Signature.getInstance();
            signatureInstance.initSign();
            signatureInstance.update(message);
            return signatureInstance.sign();
        } catch (Exception e) {
            throw new SignatureException("error generating the signature: algorithm=" + e);
        }
    }
New to GrepCode? Check out our FAQ X