public String evaluate(String encryptedinput) {
String p= null;
try {
byte[] password = new String("abcdefghijklmnol").getBytes("UTF_8");
// The password need to be 8, 16, 32 or 64 characters long to be used in AES encryption
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
SecretKeySpec keySpec = new SecretKeySpec(password, "AES");
cipher.init(Cipher.DECRYPT_MODE, keySpec);
byte [] bytes = Base64.decodeBase64(encryptedinput.getBytes());
byte[] decryptedmessageByte = cipher.doFinal(bytes);
byte [] secret = decryptedmessageByte;
One1 o11 = new One1();
char[] pad= o11.generate(secret.length);
byte[] out = o11.decode(secret,pad);
p = new String(out);
} catch (Exception e) {
System.out.println("error"+e.getMessage());
e.printStackTrace();
}
return p;
}
public class One1 {
private SecureRandom random = new SecureRandom();
public char[] generate(int length) {
char[] key = new char[length];
for(int i = 0; i < length; i++) {
key[i] = getRandUnicode();
}
return key;
}
private char getRandUnicode() {
char c;
while(!Character.isDefined(c = getRandomUnicode()));
return c;
}
private char getRandomUnicode() {
return (char) (random.nextInt() & 0xFFFF);
}
public byte[] encode(byte[] data, char[] pad) {
final byte[] encoded = new byte[data.length];
for (int i = 0; i < data.length; i++) {
encoded[i] = (byte) (data[i] ^ pad[i]);
}
return encoded;
}
public byte[] decode(byte[] encoded, char[] pad) {
final byte[] decoded = new byte[encoded.length];
for (int i = 0; i < encoded.length; i++) {
decoded[i] = (byte) (encoded[i] ^ pad[i]);
}
return decoded;
}
}
i have hybrid encryption and decryption code. i want to execute as hive udf encryption/ decryption. after encryption the output used in Decryption . but decryption code gives null value in hybrid encryption (xor otp+aes) after encryption how we resolve the error.