我正在开发一个应用程序,它使用一个授权密钥来使用volley将用户连接到应用服务器。为了识别授权密钥,必须使用授权密钥本身和用户试图从服务器发起的操作对其进行解码,我有下面编码授权密钥的第一行代码,以及使用编码的其他区域:
String authkey="xxxgafjeusjsj" ;
String action ="pay" ;
String auth=authkey+action
String Authkey=Base64.getEncoder().encodeToString(auth_.getBytes());
.....
return Base64.getEncoder().encodeToString(signature);
......
PKCS8EncodedKeySpec keySpecPKCS8 = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(privateKeyContent));上面的代码很好,但是最后3行只能用于api 26和以上的设备。在最后3行代码中,我可以使用其他代码吗?我被建议使用‘导入android.util.Base64;’而不是'Java.util.Base64‘,但它返回的错误不能解决方法getEncoder()请帮助
发布于 2019-10-24 18:09:46
I被建议使用‘导入android.util.Base64;’而不是'Java.util.Base64‘,但它返回的错误不能解决方法getEncoder()
android.util.Base64的encodeToString等价于getEncoder().encode(args)
你可以用
String Authkey= "";
if (VERSION.SDK_INT >= 26) {
Authkey = Base64.getEncoder().encode(auth_.getBytes()).toString();
} else {
Authkey = android.util.Base64.encodeToString(auth_.getBytes(), 0)
}https://stackoverflow.com/questions/58546896
复制相似问题