Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. import javax.crypto.Mac;
  2. import javax.crypto.spec.SecretKeySpec;
  3. import org.apache.commons.codec.binary.Base64;
  4.  
  5. public class CRC_Example {
  6. public static void main(String[] args) {
  7. try {
  8. String consumer_secret = "secret";
  9. String crc_token = "Message";
  10.  
  11. Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
  12. SecretKeySpec secret_key = new SecretKeySpec(consumer_secret.getBytes("UTF-8"), "HmacSHA256");
  13. sha256_HMAC.init(secret_key);
  14.  
  15. String hash = Base64.encodeBase64String(sha256_HMAC.doFinal(crc_token.getBytes("UTF-8")));
  16.  
  17. System.out.println("sha256=" + hash);
  18. }
  19. catch (Exception e){
  20. System.out.println("Error");
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement