I have a
String X = 0110100001100101011011000110110001101111530940929e959001f70dd4da5f5cc3b373165781
i first make String X into a byte [] by X.getBytes(); and i go through a RC4 encryption using this..
public static byte[] RC4(byte[] x,byte[] keyBytes)
{
byte[] e = null;
try
{
SecureRandom sr = new SecureRandom(keyBytes);
KeyGenerator kg = KeyGenerator.getInstance(algorithm);
kg.init(sr);
SecretKey sk = kg.generateKey();
Cipher enCipher = Cipher.getInstance("RC4");
enCipher.init(Cipher.ENCRYPT_MODE,sk);
e = enCipher.doFinal(plaintext);
}
catch(Exception ex)
{
ex.printStackTrace();
}
return e;
}
EDIT**
After the encryption i used cipher = encrpyted.toString();
This returns me a value of cipher = [B@a1c582
after which i try to run a decrypt using RC4, and a toString function to try and get back String X's original value which is listed above, but to no avail..
what i have done.. edit**
//the reason i send using string is due to me having a client server architecture restriction on buffered writer, and this is the receiving side
message = stdIn.readLine();
System.out.println("Message received : " + message);
byte [] kc = key.getBytes();
byte [] decrypt = message.getBytes();
byte [] decryptC = EncryptionScheme.decrypt(decrypt, kc);
X = new String(decryptC);
System.out.println("String X = " + X);
Message received : [B@a1c582
String X = ����,��
Is there any way to resolve this? i wish to get back the string of String X = 0110100001100101011011000110110001101111530940929e959001f70dd4da5f5cc3b373165781
decryption algorithm
public static byte[] decrypt(byte[] ciphertext,byte[] keyBytes)
{
byte de[] = null;
try
{
SecureRandom sr = new SecureRandom(keyBytes);
KeyGenerator kg = KeyGenerator.getInstance(algorithm);
kg.init(sr);
SecretKey sk = kg.generateKey();
Cipher deCipher = Cipher.getInstance("RC4");
deCipher.init(Cipher.DECRYPT_MODE,sk);
de = deCipher.doFinal(ciphertext);
}
catch(Exception e)
{
e.printStackTrace();
}
return de;
}