我有一个应用程序客户端/服务器,使用下面的代码在客户端加密文件:
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
此后,我通过SSL连接将编码后的文件发送到服务器,服务器尝试使用下一个代码对其进行编码:
private static byte[] cifrador(byte[] file) throws Exception {
String provider = "SunJCE";
String algorithm = "RSA";
String transfor = "/ECB/PKCS1Padding";
/************************************************************
* Xerar e almacear a clave
************************************************************/
// Obter a clave publica do trustStore
KeyStore ks = KeyStore.getInstance("JCEKS");
ks.load(new FileInputStream(pathCliente + TrustStore), password.toCharArray());
PublicKey publicKeyServer = ks.getCertificate("serverkey").getPublicKey();
Cipher cipher = Cipher.getInstance(algorithm + transform);
cipher.init(Cipher.ENCRYPT_MODE, publicKeyServer);
byte[] encodedFile = cipher.update(file);
return encodedFile;
}
使用方法public static byte[] descifrador(byte[] encodedFile) throws Exception {
String provider = "SunJCE";
String algorithm = "RSA";
String transform = "/ECB/PKCS1Padding";
char[] key_password = password.toCharArray();
KeyStore ks = KeyStore.getInstance("JCEKS");
ks.load(new FileInputStream(path + KeyStore), key_password);
KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry)
ks.getEntry("serverkey",
new KeyStore.PasswordProtection(key_password));
PrivateKey privateKeyServer = (PrivateKey) ks.getKey("serverkey", key_password);
Cipher decoder = Cipher.getInstance(algorithm + transform);
decoder.init(Cipher.DECRYPT_MODE, privateKeyServer);
// byte[] decodedFile = decoder.update(encodedFile);
byte[] decodedFile = decoder.doFinal(encodedFile);
return decodedFile;
}
,我得到decoder.update(encodedFile)
;使用方法Null
,我得到了下一个错误:
decoder.doFinal(encodedFile)
请提出一些想法,感谢您的回答