Hello,
I have the following problem: I try to encrypt a byte array with a RSA public key cipher and want to get the same encrypted byte-array for every invocation of doFinal().
Purpose*
Two people (a and b) maybe share the same secret. Yet they do not trust each other until they have confirmed that they share the same secret. To check if both share the same secret the following protocol shall be applied (over an unsecure communication channel using person c which they do not trust either). There is also no other person that may assist in establishing trust (i.e. building chains of trust).
(1) a generates RSA public / private key
(2) a encrypts her secret with the RSA public key
(3) a sends the encrypted secret with her RSA public key to b
(4) b uses the RSA public key of a to encrypt his secret
(5) if the encrypted secret of a matches the encrypted secret of b, then do (6), otherwise a and b do not share the same secret, thus they stop conversatzion
(6) b generates his own RSA public / private key
(7) b encrypts the (unencrypted) secret with his private key
(8) b encrypts his secret (encrypted with his private key), as well as his public key, with the public key of a
(9) b sends his secret (encrypted with his private key) and his public key to a
(10) a decrypts the secret and public key of b with her private key
(11) a decrypts the secret with the public key of b
(12) a double-checks if the secret received from b acually meets the one a knows => trust established, finish
So, what I want to achieve is that the following code prints "true":
byte[] potentialSecret = new byte[]{1, 2, 3, 4, 5};
KeyPairGenerator kpg = KeyPairGenerator.getInstance(RSA);
kpg.initialize(512);
KeyPair kp = kpg.generateKeyPair();
PublicKey key = kp.getPublic();
Cipher c = Cipher.getInstance(RSA);
c.init(Cipher.ENCRYPT_MODE, key);
System.out.println(Arrays.equals(c.doFinal(xy), c.doFinal(xy)));
I tried to "mess around" with initialization vectors but always ended with exceptions of various kind.
Thank you very much
Bjoern
PS: btw, how do I markup code? This is my first posting in Oracle forums.