我正在尝试下面的 Java 代码:
byte[] data = Base64.getEncoder().encode((key + number + ts + role).getBytes("UTF-8"));
hash = Crypto.hmacSha256(data, secret.getBytes("UTF-8"));
String s = key + "." + number +"."+ ts +"."+ role + "." + Base64.getEncoder().encodeToString(hash);
result = Base64.encodeBase64URLSafeString(s.getBytes("UTF-8"));
但我不知道应该导入哪个包才能使用 Crypto.hmacSha256。我导入了 java.util.Base64;但是好像没有encodeBase64URLSafeString,这个方法在哪里?
最佳答案
您正在寻找 commons-codec 库和此方法 https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/binary/Base64.html#encodeBase64URLSafe(byte[])
关于java - 我应该导入哪些包才能使用 Crypto 和 encodeBase64URLSafeString?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43771893/