Advertisement
Guest User

Untitled

a guest
Jul 6th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. protected String hashToString(String serializedModel, byte[] key) {
  2.  
  3. String result = null;
  4.  
  5. Mac sha512_HMAC;
  6.  
  7. try {
  8.  
  9. sha512_HMAC = Mac.getInstance("HmacSHA512");
  10.  
  11. SecretKeySpec secretkey = new SecretKeySpec(key, "HmacSHA512");
  12.  
  13. sha512_HMAC.init(secretkey);
  14.  
  15. byte[] mac_data = sha512_HMAC.doFinal(serializedModel.getBytes("UTF-8"));
  16.  
  17. // if this next line not compiled, test the second line.
  18. result = Base64.encodeBase64String(mac_data);
  19. //result = Base64.encodeToString(mac_data, Base64.DEFAULT);
  20.  
  21. }catch(Exception e){
  22. }
  23.  
  24. return result;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement