Hello
I have problem again.
I need to encrypt data with RSA public key. After loading public key I initialize cipher and encrypt data with my public key.
There are input data:
//public key DER format, I read it from file in binary format
305a300d06092a864886f70d01010105000349003046024100aa36abce88acfdff55523c7fc4523f90efa00df3774a259f2e62b4c5d99cb5adb300a0285e5301930e0c70fb6876939ce616ce624a11e0086d341ebcaca0a1f5020111
byte [] publicKeyData = Hex.decode("")
byte [] input = Hex.decode("54859b342c49ea2a");
SecureRandom rnd = new SecureRandom(Hex.decode("aafd12f659cae63489b479e5076ddec2f06cb58f"));
File f = new File("C:\\test\\oaep\\public_Bin.dat");
DataInputStream dis = new DataInputStream(new FileInputStream(
f));
byte[] pubKeyBytes = new byte[ (int) f.length()];
dis.readFully(pubKeyBytes);
X509EncodedKeySpec pubSpec = new X509EncodedKeySpec(pubKeyBytes);
RSAPublicKey publicKey = (RSAPublicKey) keyFactory.generatePublic(pubSpec);
dis.close();
Cipher cipher = Cipher.getInstance("1.2.840.113549.1.1.7","BC");
//Cipher cipher = Cipher.getInstance("RSAES-OAEP-SHA1","CryptixCrypto");
cipher.init(Cipher.ENCRYPT_MODE, publicKey,rnd);
byte [] output = cipher.doFinal(input);
My output data are:
4267cfd55b8a241409bfc75b4b7be44e171a8ac0c9fa5fab06cc62bf681ee0bb3776becfc0e9a6faaa9236235de1d15314571ff1eb070aca2d990ccd992a7fa2
But expected data shall be :
1b8f05f9ca1a79526e53f3cc514fdb892bfb9193231e78b992e68d50a480cb5233895c74958d5d02ab8c0fd040eb5844b005c39ed8274a9dbfa80671409439d2
I used first test case on "ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1v2/p1ovect1.txt".This file contains validation data for mentioned algorithm.
Can somebody know where is problem in my source code. Both providers gave same results.
Thanks