Hellos.
Am having difficulty solving my problem as follows:
Im trying to write a program to perform DES encryption. I do not wish to generate a DES key using the SecretKey method as i have my own set of keys. I have the following:
plainText (8 bytes) in hex representation.
key(7 bytes) in hex representation.
Both are stored in the form of byte arrays.
Then i do a hex2Byte conversion for both plainText and key.
and i passed these 2 variables into my try block as shown below. Is it correct?
Nothing is displayed after i execute the program. Pls help! Thanks :)
Am having difficulty solving my problem as follows:
Im trying to write a program to perform DES encryption. I do not wish to generate a DES key using the SecretKey method as i have my own set of keys. I have the following:
plainText (8 bytes) in hex representation.
key(7 bytes) in hex representation.
Both are stored in the form of byte arrays.
Then i do a hex2Byte conversion for both plainText and key.
and i passed these 2 variables into my try block as shown below. Is it correct?
Nothing is displayed after i execute the program. Pls help! Thanks :)
Code:
try
{
byte[] cipherText = null;
//init cipher
KeySpec ks = new DESKeySpec(key);
SecretKeyFactory kf =SecretKeyFactory.getInstance("DES");
SecretKey ky = kf.generateSecret(ks);
Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, ky);
//encrypt
cipherText = cipher.doFinal(plainText);
System.out.println("Key: " +key);
System.out.println("PlainText:"+plainText);
//display cipherText
System.out.println("CipherText: " + byte2Hex(cipherText));
}
catch (Exception e) {}
Comment