Last active
February 4, 2020 09:25
-
-
Save glides/3eec98625a6f88c9894ec56a9b2cf900 to your computer and use it in GitHub Desktop.
Encrypt AES-256 in Boo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# AES-256 with key encryption function Boo Lang | |
public static def encrypt(cleartext as (byte), key as string) as (byte): | |
using aesAlg = Aes.Create(): | |
salt = array(byte,[0x12,0x35,0x56,0x78,0x90,0xAB,0xAD,0xEF,0xDD,0x31]) | |
rfc = Rfc2898DeriveBytes(key,salt) | |
aesAlg.Padding = PaddingMode.PKCS7 | |
aesAlg.KeySize = 256 | |
aesAlg.Key = rfc.GetBytes(32) | |
aesAlg.IV = rfc.GetBytes(16) | |
encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV) | |
using encryptedData = MemoryStream(): | |
using cryptoStream = CryptoStream(encryptedData, encryptor, CryptoStreamMode.Write): | |
cryptoStream.Write(cleartext, 0, cleartext.Length) | |
cryptoStream.FlushFinalBlock() | |
return encryptedData.ToArray() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment