Cryptography Reference
In-Depth Information
The makeKeys() method is called early by the constructor to set up the sender's public
and private keys. Since we use RSA with salt, each communicant can use the enciphering
exponent
= 3. Of course, each has its own modulus, and deciphering key, which are cre-
ated here. Strong primes are used.
e
private void makeKeys() {
PrimeGenerator pg=new PrimeGenerator(513,10,sr);
do {
p=pg.getStrongPrime();
} while(p.subtract(BigIntegerMath.ONE).mod(BigIntegerMath.THREE).equals
(BigIntegerMath.ZERO));
do {
q=pg.getStrongPrime();
} while(q.subtract(BigIntegerMath.ONE).mod(BigIntegerMath.THREE).equals
(BigIntegerMath.ZERO));
modulus=p.multiply(q);
//Use 3 as enciphering exponent - OK since we are using salt
decipherExp=BigIntegerMath.THREE.modInverse
(p.subtract(BigIntegerMath.ONE).multiply(q.subtract(BigIntegerMath.ONE)));
ciphertextBlockSize=(modulus.bitLength()-1)/8+1;
plaintextBlockSize=ciphertextBlockSize-6;
}
Note that the plaintext block size is computed as 6 bytes less than the ciphertext block
size. This is because we need to take off 1 byte to get the plaintext under the modulus (all
plaintext blocks must be smaller than the modulus), 4 bytes for the salt, and 1 byte for a pad
byte (remember that the decipher method always removes padding).
Once the keys exist, they can be sent to the other communicant. This task is handled
here by the exchangeKeys() method. It will be called from a point in the program soon after
a socket has been set up between the two parties.
private void exchangeKeys() {
try {
byte[] buffer=new byte[ciphertextBlockSize];
input.read(buffer);
recipModulus=new BigInteger(1,buffer);
output.write(modulus.toByteArray());
} catch (IOException ioe) {
System.err.println(“Error establishing keys”);
}
}
Two components on this window can generate an ActionEvent object:
1.
The user hit the enter key while in the message entry field. This means a message is to
be sent. The text is captured from the field, enciphered using the recipient's public key,
and sent down the output stream.
Search WWH ::




Custom Search