/// <summary> /// Decrypts the Data into a string /// </summary> /// <param name="locked">locked Data to be decrypted</param> public byte[] UnlockBytes(ILocked locked) { if (locked == null) { throw new ArgumentNullException(nameof(locked)); } return(SecretKeyBox_AES.Open(locked.Ciphertext, locked.Nonce, key)); }
/// <summary> /// Encrypts the Data /// /// IMPORTANT: this method does NOT provide integrity. Tampered messages will be decrypted without throwing an exception /// /// Uses AES in CBC mode with PKCS7 padding /// </summary> /// <param name="data">Data to be encrypted</param> public ILocked Lock(byte[] data) { if (data == null || data?.Length == 0) { throw new ArgumentNullException(nameof(data)); } Nonce nonce; var locked = SecretKeyBox_AES.Create(data, key, out nonce); return(new Locked(locked, nonce)); }