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.45 KB | None | 0 0
  1. public class Script {
  2.    public static void main(String[] args) {
  3.       String resultString = "iflipit.mondadorieducation.it/sync/getEditorNotes.php?srd=&srnm=&iss=TVM1MDQ1MV8yMDE1&t=1465141330757&track_os=ios&track_osversion=9.3.2&track_device=tablet&track_uid=&track_appversion=4.3.4";
  4.       String privateKey = "og8WGTtmeFaZ7eNVH4EC9ueTwNx3KSKzenio9ePe2G2yHHi8NIsxmMAlsnHZiYPD";
  5.       System.out.println(generate_HMAC_SHA1(resultString, privateKey));
  6.    }
  7.  
  8.     public static String sha1Hash(String toHash) {
  9.         String hash = null;
  10.         try {
  11.             MessageDigest digest = MessageDigest.getInstance("SHA-1");
  12.             digest.update(toHash.getBytes(), 0, toHash.length());
  13.             hash = new BigInteger(1, digest.digest()).toString(16);
  14.         } catch (NoSuchAlgorithmException e) {
  15.             e.printStackTrace();
  16.         }
  17.         return hash;
  18.     }
  19.  
  20.     public static String generate_HMAC_SHA1(String daFirmare, String secretKey) throws InvalidKeyException, NoSuchAlgorithmException {
  21.         return binary2ASCIIHex(calcSHA1MAC(Base64.decode(secretKey, 0), daFirmare));
  22.     }
  23.  
  24.     private static byte[] calcSHA1MAC(byte[] abyte0, String s) throws NoSuchAlgorithmException, InvalidKeyException {
  25.         byte[] abyte1 = null;
  26.         SecretKeySpec secretkeyspec = new SecretKeySpec(abyte0, "DES");
  27.         Mac mac = Mac.getInstance("HmacSHA1");
  28.         mac.init(secretkeyspec);
  29.         return mac.doFinal(s.getBytes());
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement