I am using the below code
public byte[] encrypt(byte[] unencryptedString,String k)throws Exception {
String encryptedString = null;
String k1 = String.format("%024d", Integer.parseInt(k));
myEncryptionKey = k1;
myEncryptionScheme = DESEDE_ENCRYPTION_SCHEME;
arrayBytes = myEncryptionKey.getBytes(UNICODE_FORMAT);
ks = new DESedeKeySpec(arrayBytes);
skf = SecretKeyFactory.getInstance(myEncryptionScheme);
cipher = Cipher.getInstance(myEncryptionScheme);
key = skf.generateSecret(ks);
try {
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] plainText =
unencryptedString/*.getBytes(UNICODE_FORMAT)*/;
byte[] encryptedText = cipher.doFinal(plainText);
// encryptedString = new String(Base64.encodeBase64(encryptedText));
} catch (Exception e) {
e.printStackTrace();
}
return encryptedText;
}
The return statement gives the following error:
encryptedText cannot be resolved to a variable
encryptedTextis in the try block. You need to move the declaration.nullis a bad idea, and moving the return statement might be better, but it depends upon specifications outside the scope of the posted code. It is declared to throw a genericException, which is also a bad idea, but doesn't do so if there is an issue with thecipher.doFinal, so returningnullwould be the only indicator of a problem given the code, I think.