Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.google.code.springcryptoutils.core.signature;
 
The default implementation for verifying the authenticity of messages using digital signatures.

Author(s):
Mirko Caserta (mirko.caserta@gmail.com)
public class VerifierImpl implements Verifier {
    private PublicKey publicKey;
    private String algorithm = "SHA1withRSA";

    
The public key for verifying the message.

Parameters:
publicKey the public key
    public void setPublicKey(PublicKey publicKey) {
        this. = publicKey;
    }

    
The signature algorithm. The default is SHA1withRSA.

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

    
Verifies the authenticity of a message using a digital signature.

Parameters:
message the original message to verify
signature the digital signature
Returns:
true if the original message is verified by the digital signature
    public boolean verify(byte[] messagebyte[] signature) {
        try {
            // this way signatureInstance should be thread safe
            final Signature signatureInstance = Signature.getInstance();
            signatureInstance.initVerify();
            signatureInstance.update(message);
            return signatureInstance.verify(signature);
        } catch (Exception e) {
            throw new SignatureException("error verifying signature"e);
        }
    }
New to GrepCode? Check out our FAQ X