I use this key as 3DES key to exchange with RSA---> private static final byte[] MY_KEY = "5oquil2oo2vb63e8ionujny6l9k8".getBytes();
public byte[] encrypt_des(String message) throws Exception {
byte[] encrypted = RSA.this.encrypt(MY_KEY);
final MessageDigest md = MessageDigest.getInstance("md5");
final byte[] digestOfPassword = md.digest(RSA.this.encrypt(MY_KEY));
final byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
for (int j = 0, k = 1; k < encrypted.length;) {
keyBytes[k++]=keyBytes[j++];
}
final SecretKey key = new SecretKeySpec(keyBytes, "DESede");
final IvParameterSpec iv = new IvParameterSpec(new byte[8]);
final Cipher cipher = Cipher.getInstance("DESede/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, key, iv);
final byte[] plainTextBytes = message.getBytes("utf-8");
final byte[] cipherText = cipher.doFinal(plainTextBytes);
// final String encodedCipherText = new sun.misc.BASE64Encoder()
// .encode(cipherText);
return cipherText;
}
And this error appears at the output---> Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 24 out of bounds for length 24 at RSA.encrypt_des(RSA.java:100) at RSA.main(RSA.java:62). How can I solve this error ? and how can I i use encrypted/decrypted key from RSA in 3DES (this method above)?