Documente Academic
Documente Profesional
Documente Cultură
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.xml.bind.DatatypeConverter;
/**
* This example program shows how AES encryption and decryption can be done in Java.
* Please note that secret key and encrypted text is unreadable binary and hence
* */
/**
* 2. Get a secret key (printed in hexadecimal form). In actual use this must
* */
System.out.println("Descrypted Text:"+decryptedText);
}
/**
* gets the AES encryption key. In your actual programs, this should be safely
* stored.
* @return
* @throws Exception
*/
return secKey;
/**
* @param plainText
* @param secKey
* @return
* @throws Exception
*/
aesCipher.init(Cipher.ENCRYPT_MODE, secKey);
return byteCipherText;
}
/**
* Decrypts encrypted byte array using the key used for encryption.
* @param byteCipherText
* @param secKey
* @return
* @throws Exception
*/
aesCipher.init(Cipher.DECRYPT_MODE, secKey);
/**
* @param hash
* @return
*/
return DatatypeConverter.printHexBinary(hash);