Skip to content

Instantly share code, notes, and snippets.

@glides
Last active February 4, 2020 09:25
Show Gist options
  • Save glides/3eec98625a6f88c9894ec56a9b2cf900 to your computer and use it in GitHub Desktop.
Save glides/3eec98625a6f88c9894ec56a9b2cf900 to your computer and use it in GitHub Desktop.

Revisions

  1. glides revised this gist Feb 4, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions encrypt.boo
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # 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])
  2. glides created this gist Feb 4, 2020.
    16 changes: 16 additions & 0 deletions encrypt.boo
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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()