Ami*_*oda 2 java encryption decode
在我的应用程序中,我正在编码一个字符串,然后生成一个MAC ID(使用javax.crypto.Mac).但我试图解码它,但我不能.你能帮我解决.你能指出我做错了哪里?
码
String userid = "AmilaI";
String time = gmtFormat.format(now)+ "Z";
String algorithmKey = time + userid;
SecretKeySpec sks = new SecretKeySpec(algorithmKey.getBytes("UTF-8"), "HmacSHA1");
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(sks);
byte[] hashBytes = mac.doFinal(route.getBytes("UTF-8"));
String hmac = Base64.encodeBase64String(hashBytes);
hmac = hmac.replaceAll("\r\n", "");
System.out.println("Encrypted "+ hmac );
byte[] decoded = Base64.decodeBase64(hmac);
System.out.println("Decrypted " + new String(decoded, "UTF-8") + "\n");
Run Code Online (Sandbox Code Playgroud)
如何反转路径并获取alogorithmKey,以便通过解密获取用户ID?
| 归档时间: |
|
| 查看次数: |
2604 次 |
| 最近记录: |