Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.crypto.Cipher
- import javax.crypto.KeyGenerator
- import java.security.Key
- String input = "This is PlainText!"
- println "==>> Plain text: ${input} <<=="
- String algorithm = "DESede"
- Cipher cipher = Cipher.getInstance(algorithm)
- Key generatedKey = KeyGenerator.getInstance(algorithm).generateKey()
- String encodedGeneratedKey = generatedKey.encoded.encodeBase64()
- println "==>> Base64 encoded symkey: ${encodedGeneratedKey} <<=="
- cipher.init(Cipher.ENCRYPT_MODE, generatedKey)
- byte[] cipherText = cipher.doFinal(input.bytes)
- println "==>> Ciphertext: ${new String(cipherText)} <<=="
- cipher.init(Cipher.DECRYPT_MODE, generatedKey)
- String decrypted = new String(cipher.doFinal(cipherText))
- println "==>> Decrypted text: ${decrypted} <<=="
- assert input == decrypted
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement