Advertisement
Guest User

Untitled

a guest
Jun 5th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. public class Script {
  2.    public static void main(String[] args) {
  3.       String privateKey = "og8WGTtmeFaZ7eNVH4EC9ueTwNx3KSKzenio9ePe2G2yHHi8NIsxmMAlsnHZiYPD";
  4.       System.out.println(generate_HMAC_SHA1(resultString, privateKey));
  5.    }
  6.  
  7.     public static String sha1Hash(String toHash) {
  8.         String hash = null;
  9.         try {
  10.             MessageDigest digest = MessageDigest.getInstance("SHA-1");
  11.             digest.update(toHash.getBytes(), 0, toHash.length());
  12.             hash = new BigInteger(1, digest.digest()).toString(16);
  13.         } catch (NoSuchAlgorithmException e) {
  14.             e.printStackTrace();
  15.         }
  16.         return hash;
  17.     }
  18.  
  19.     public static String generate_HMAC_SHA1(String daFirmare, String secretKey) throws InvalidKeyException, NoSuchAlgorithmException {
  20.         return binary2ASCIIHex(calcSHA1MAC(Base64.decode(secretKey, 0), daFirmare));
  21.     }
  22.  
  23.     private static byte[] calcSHA1MAC(byte[] abyte0, String s) throws NoSuchAlgorithmException, InvalidKeyException {
  24.         byte[] abyte1 = null;
  25.         SecretKeySpec secretkeyspec = new SecretKeySpec(abyte0, "DES");
  26.         Mac mac = Mac.getInstance("HmacSHA1");
  27.         mac.init(secretkeyspec);
  28.         return mac.doFinal(s.getBytes());
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement