Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我应该导入哪些包才能使用Crypto和encodeBase64URLSafeString?_Java_Algorithm_Import_Package_Encode - Fatal编程技术网

Java 我应该导入哪些包才能使用Crypto和encodeBase64URLSafeString?

Java 我应该导入哪些包才能使用Crypto和encodeBase64URLSafeString?,java,algorithm,import,package,encode,Java,Algorithm,Import,Package,Encode,我正在尝试以下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 +

我正在尝试以下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编解码器库和该方法

您可能正在查找commons编解码器库我如何导入该方法?我尝试导入org.apache.commons.codec.binary.Base64,但我得到一个错误“导入org.apache无法解决”,您需要将其添加到ClassPath中谢谢!您知道Crypto.hmacSha256吗?是否也有用于此的外部库?看起来您正在尝试使用SHA256计算哈希?Java为此内置了API。你可以用像