Cryptography/CafeLib.Cryptography/AesEncryption.cs
/// <summary>
/// Applies AES decryption to data encrypted with AesEncrypt and the specified key.
/// The actual iv used is obtained from the first 16 bytes of data if null.
/// </summary>
/// <param name="data"></param>
/// <param name="key"></param>
/// <param name="iv">The IV to use. If null, the first 16 bytes of data are used.</param>
/// <param name="ivLength">IV length</param>
/// <returns>Decryption of data.</returns>
Applies AES decryption to data encrypted with AesEncrypt and the specified key.
The actual iv used is obtained from the first 16 bytes of data if null.
Applies AES decryption to data encrypted with AesEncrypt and the specified key . The actual iv used is obtained from the first 16 bytes of data if null .
public static byte[] Decrypt(ReadOnlyByteSpan data, byte[] key, byte[] iv = null, int ivLength = DefaultVectorLength)
        {
            if (iv == null)
            {
                iv = data[..ivLength];
                data = data[ivLength..];
            }
            var aes = CreateAes(key, iv, false);
            var aesData = aes.DoFinal(data);
            return aesData;
        }
public static byte [ ] Decrypt ( ReadOnlyByteSpan data , byte [ ] key , byte [ ] iv = null , int ivLength = DefaultVectorLength ) { if ( iv == null ) { iv = data [ .. ivLength ] ; data = data [ ivLength .. ] ; } var aes = CreateAes ( key , iv , false ) ; var aesData = aes . DoFinal ( data ) ; return aesData ; }
Applies AES decryption to data encrypted with AesEncrypt and the specified key.
Applies AES decryption to data encrypted with AesEncrypt and the specified key .
Decryption of data.
Decryption of data .
data
ReadOnlyByteSpan
None
key
byte[]
None
iv
byte[]
The IV to use. If null, the first 16 bytes of data are used.
The IV to use . If null the first 16 bytes of data are used .
ivLength
int
None