0

I am trying below Java code:

          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"));  

But I don't know which package I should import to be able to use Crypto.hmacSha256. And I imported java.util.Base64; but it seems it doesn't have encodeBase64URLSafeString, where is this method?

spspli
  • 3,128
  • 11
  • 48
  • 75
  • You are probably looking for commons-codec library https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/binary/Base64.html#encodeBase64URLSafe(byte[]) – jmj May 04 '17 at 00:20

1 Answers1

1

You are looking for commons-codec library and this method https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/binary/Base64.html#encodeBase64URLSafe(byte[])

jmj
  • 237,923
  • 42
  • 401
  • 438