VerifySignature Problem in JAVA
<p>I have implemented a sample code to generate Hash and Sign and Verify the Signature as follows:
But when iam trying to verify the Signature, its throwing me false .it is not able to verify the Signature.</p>

<p>Am I following the correct procedure .Please do suggest </p>

<p>The actual scenario i need is i want to calculate the hash of a file ,sign the hash and decrypt the signature, so i can get the hash which can be verified with the original hash.</p>

<p>Can u please suggest me the APIS to Use and if possible a sample program to do that.</p>

<pre><code>public class Temp {
    public static void main(String args[]) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, SignatureException{

        KeyPairGenerator signkeygen = KeyPairGenerator.getInstance("RSA");  
        signkeygen.initialize(2048);//The argument specifies the length of the key in bits
        KeyPair signkey = signkeygen.generateKeyPair();
        PublicKey sign_publicKey = signkey.getPublic();
        PrivateKey sign_privateKey = signkey.getPrivate();

        String test = "hai";

        Signature mysign = Signature.getInstance("SHA1withRSA");
        mysign.update(test.getBytes());
        byte[] byteSignedData = mysign.sign();
        Signature vSign = Signature.getInstance("SHA1withRSA");
        vSign.initVerify(sign_publicKey); 
        vSign.update(byteSignedData);

        boolean signStatus = vSign.verify(byteSignedData);
        System.out.println(signStatus);
        ...
</code></pre>
