2017-05-04 62 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 []) –

回答

相關問題