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

Which packages I should import to be able to use Crypto and encodeBase64URLSafeString?

我正在尝试以下 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[])