You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import*ascryptofrom'crypto';functiondecryptData(encryptedData: string,key: Buffer,iv: Buffer): string{constdecipher=crypto.createDecipheriv('aes-256-cbc',key,iv);letdecryptedData=decipher.update(encryptedData,'base64','utf-8');decryptedData+=decipher.final('utf-8');returndecryptedData;}// Example usage:constencryptedData='encrypted-data-here';// Use the same key and IV used for encryptionconstkey=/* Same key used for encryption */;constiv=/* Same IV used for encryption */;constdecryptedData=decryptData(encryptedData,key,iv);console.log('Decrypted Data:',decryptedData);
using System;using System.IO;using System.Security.Cryptography;using System.Text;classProgram{staticvoidMain(){stringencryptedData="encrypted-data-here";byte[]key=/* Same key used for encryption */;byte[]iv=/* Same IV used for encryption */;stringdecryptedData= DecryptData(encryptedData, key, iv);
Console.WriteLine("Decrypted Data: "+decryptedData);}staticstringDecryptData(stringencryptedData,byte[]key,byte[]iv){using(AesaesAlg= Aes.Create()){
aesAlg.Key =key;
aesAlg.IV =iv;ICryptoTransformdecryptor= aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);using(MemoryStreammsDecrypt=new MemoryStream(Convert.FromBase64String(encryptedData))){using(CryptoStreamcsDecrypt=new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)){using(StreamReadersrDecrypt=new StreamReader(csDecrypt)){return srDecrypt.ReadToEnd();}}}}}}
fromcryptography.hazmat.backendsimportdefault_backendfromcryptography.hazmat.primitives.ciphersimportCipher, algorithms, modesfromcryptography.hazmat.primitivesimportpaddingfrombase64importb64decodedefdecrypt_data(encrypted_data, key, iv):
cipher=Cipher(algorithms.AES(key), modes.CFB(iv), backend=default_backend())
decryptor=cipher.decryptor()
ciphertext=b64decode(encrypted_data)
decrypted_data_padded=decryptor.update(ciphertext) +decryptor.finalize()
unpadder=padding.PKCS7(algorithms.AES.block_size).unpadder()
decrypted_data=unpadder.update(decrypted_data_padded) +unpadder.finalize()
returndecrypted_data.decode('utf-8')
# Example usage:encrypted_data="encrypted-data-here"# Use the same key and IV used for encryptionkey=/*Samekeyusedforencryption*/iv=/*SameIVusedforencryption*/decrypted_data=decrypt_data(encrypted_data, key, iv)
print("Decrypted Data:", decrypted_data)
require'openssl'require'base64'defdecrypt_data(encrypted_data,key,iv)cipher=OpenSSL::Cipher.new('AES-256-CBC')cipher.decryptcipher.key=keycipher.iv=ivdecrypted_data=cipher.update(Base64.strict_decode64(encrypted_data)) + cipher.finalreturndecrypted_dataend# Example usage:encrypted_data='encrypted-data-here'# Use the same key and IV used for encryptionkey=# Same key used for encryptioniv=# Same IV used for encryptiondecrypted_data=decrypt_data(encrypted_data,key,iv)puts"Decrypted Data: #{decrypted_data}"
Windows Batch programming + OpenSSL tool
@echooffsetlocalenabledelayedexpansionset"dataToEncrypt=Hello, World!"set"keyFile=key.bin"set"ivFile=iv.bin"set"plaintextFile=plaintext.txt"set"encryptedFile=encrypted.enc"rem Generate a random key and IV
openssl rand -out !keyFile!32
openssl rand -out !ivFile!16rem Save the data to a plaintext fileecho!dataToEncrypt!>!plaintextFile!rem Encrypt the data using OpenSSL
openssl enc -aes-256-cbc -e -in !plaintextFile! -out !encryptedFile! -K !keyFile! -iv !ivFile!echo Encrypted Data: !encryptedFile!endlocal
@echooffsetlocalenabledelayedexpansionset"keyFile=key.bin"set"ivFile=iv.bin"set"encryptedFile=encrypted.enc"set"decryptedFile=decrypted.txt"rem Decrypt the data using OpenSSL
openssl enc -aes-256-cbc -d -in !encryptedFile! -out !decryptedFile! -K !keyFile! -iv !ivFile!rem Read and display the decrypted dataset /p decryptedData=<!decryptedFile!echo Decrypted Data: !decryptedData!endlocal