Java SHA1 generateSHA1RSASignature(RSAPrivateKey privKey, byte[] text)

Here you can find the source of generateSHA1RSASignature(RSAPrivateKey privKey, byte[] text)

Description

Given the privateKey produce an RSA signature for the SHA1 hash of a given text.

License

Open Source License

Declaration

public static byte[] generateSHA1RSASignature(RSAPrivateKey privKey, byte[] text) 

Method Source Code


//package com.java2s;

import java.security.*;

import java.security.interfaces.RSAPrivateKey;

public class Main {
    /**//w  ww  . ja  v  a2  s  .  c o  m
     * Given the privateKey produce an RSA signature for the SHA1 hash of a given text.
     * 
     * @return
     */
    public static byte[] generateSHA1RSASignature(RSAPrivateKey privKey, byte[] text) {
        try {
            Signature mySig = Signature.getInstance("SHA1withRSA");
            mySig.initSign(privKey);
            mySig.update(text);
            return mySig.sign();
        } catch (Exception e) {
            // TODO: Improve error handling ...

            System.err.println("Exception in generateSHA1RSASignature: " + e);
            return null;
        }
    }
}

Related

  1. doSHA1(byte[] buf)
  2. doSHA1(byte[] buf, int off, int len)
  3. generateSHA1(String message)
  4. generateSHA1ChecksumFile(String filename)
  5. generateSHA1Key(String input)
  6. generateSHA1String(String stringToEncode)
  7. sha1(byte[] bytes)
  8. sha1(byte[] bytes)
  9. sha1(byte[] bytes)