此方法我已经验证了的,和 C++ openssl 中的 RC4 算法是一样的(密钥相同的情况下),
代码如下:
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
public class OpenSSLInterop {
public static byte[] decryptRC4(byte[] plainKey, byte[]
cipherText)
throws Exception {
SecretKey skeySpec = new SecretKeySpec(plainKey, "RC4");
Cipher cipher = Cipher.getInstance("RC4");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
return cipher.doFinal(cipherText);
}
}
代码来源:
http://www.mt-soft.com.ar/2007/12/21/using-openssl-rsa-and-rc4-to-exchange-encrypted-data-
from-php-to-java/