We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1
on our lab task: encrypt and decrypt text the instruction of this is we need to use
a cryptographic library (e.g., OpenSSL) to encrypt a text message using a symmetric
encryption algorithm such as AES. next is to write a script (e.g., in Python) to perform encryption and decryption operations on the text then test the encryption and decryption process to ensure that the original message can be recovered successfully.
so OpenSSL is an open-source software library that provides cryptographic functions
and tools for secure communication over computer networks. It supports various protocols and algorithms, including SSL/TLS for secure web browsing and RSA for encryption.
for cmd: openssl enc -aes-256-cbc -e -a -in sample.txt -out cipher.txt NAMI NAMI openssl enc -aes-256-cbc -d -a -in cipher.txt -out decrypt.txt NAMI NAMI
for Encryption:
encryptionCipher.init(Cipher.ENCRYPT_MODE, key) initializes the Cipher object for
encryption using the secret key generated earlier.
encryptionCipher.doFinal(messageInBytes) encrypts the input message
(messageInBytes) using the initialized Cipher object and returns the encrypted bytes.
for Decryption:
Cipher.getInstance("AES/GCM/NoPadding") is used again to create a new Cipher object
for decryption, with the same parameters as used for encryption.
decryptionCipher.init(Cipher.DECRYPT_MODE, key, spec) initializes the Cipher object
for decryption using the secret key and GCM parameters.
decryptionCipher.doFinal(messageInBytes) decrypts the input encrypted message
(messageInBytes) using the initialized Cipher object and returns the decrypted bytes.
for Base64 Encoding and Decoding:
Base64.getEncoder().encodeToString(data) is used to encode the byte array data into a Base64-encoded string. Base64.getDecoder().decode(data) is used to decode a Base64-encoded string data back into its original byte array representation.