Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Script {
- public static void main(String[] args) {
- String privateKey = "og8WGTtmeFaZ7eNVH4EC9ueTwNx3KSKzenio9ePe2G2yHHi8NIsxmMAlsnHZiYPD";
- System.out.println(generate_HMAC_SHA1(resultString, privateKey));
- }
- public static String sha1Hash(String toHash) {
- String hash = null;
- try {
- MessageDigest digest = MessageDigest.getInstance("SHA-1");
- digest.update(toHash.getBytes(), 0, toHash.length());
- hash = new BigInteger(1, digest.digest()).toString(16);
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- }
- return hash;
- }
- public static String generate_HMAC_SHA1(String daFirmare, String secretKey) throws InvalidKeyException, NoSuchAlgorithmException {
- return binary2ASCIIHex(calcSHA1MAC(Base64.decode(secretKey, 0), daFirmare));
- }
- private static byte[] calcSHA1MAC(byte[] abyte0, String s) throws NoSuchAlgorithmException, InvalidKeyException {
- byte[] abyte1 = null;
- SecretKeySpec secretkeyspec = new SecretKeySpec(abyte0, "DES");
- Mac mac = Mac.getInstance("HmacSHA1");
- mac.init(secretkeyspec);
- return mac.doFinal(s.getBytes());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement