2017-05-04 60 views
0

我想下面的Java代码:我应该导入哪些软件包才能够使用Crypto和encodeBase64URLSafeString?

  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,这个方法在哪里?

+0

您可能正在寻找公地编解码器库https://commons.apache.org/proper/commons-codec/apidocs/org/apache/ commons/codec/binary/Base64.html#encodeBase64URLSafe(byte []) –

回答

相关问题