pub fn decrypt(&self, iv: Option<&[u8]>, data: &[u8]) -> Result<Buffer> {
        let mut iv_copy = iv.map(|iv| Buffer::from(iv));
        let iv_ptr = iv_copy.as_mut().map_or(null_mut(), |iv| iv.as_mut_ptr());
        let iv_len = iv_copy.as_ref().map_or(0, |iv| iv.len() as ULONG);

        let mut plaintext_len = MaybeUninit::<ULONG>::uninit();
        unsafe {
            Error::check(BCryptDecrypt(
                self.handle.as_ptr(),
                data.as_ptr() as PUCHAR,
                data.len() as ULONG,
                null_mut(),
                iv_ptr,
                iv_len,
                null_mut(),
                0,
                plaintext_len.as_mut_ptr(),
                BCRYPT_BLOCK_PADDING,
            ))?;

            let mut output = Buffer::new(plaintext_len.assume_init() as usize);

            Error::check(BCryptDecrypt(
                self.handle.as_ptr(),
                data.as_ptr() as PUCHAR,
                data.len() as ULONG,
                null_mut(),
                iv_ptr,
                iv_len,
                output.as_mut_ptr(),
                output.len() as ULONG,
                plaintext_len.as_mut_ptr(),
                BCRYPT_BLOCK_PADDING,
            ))
            .map(|_| output)
        }
    }
/// Decrypts data using the symmetric key
///
/// The IV is not needed for [`ChainingMode::Ecb`], so `None` should be used
/// in this case.
///
/// For chaining modes needing an IV, `None` can be used and a default IV will be used.
/// This is not documented on Microsoft's website and is therefore not recommended.
///
/// # Examples
///
/// ```
/// # use win_crypto_ng::symmetric::{ChainingMode, SymmetricAlgorithm, SymmetricAlgorithmId};
/// # let algo = SymmetricAlgorithm::open(SymmetricAlgorithmId::Aes, ChainingMode::Cbc).unwrap();
/// let key = algo.new_key("0123456789ABCDEF".as_bytes()).unwrap();
/// let iv = "_THIS_IS_THE_IV_".as_bytes();
/// let ciphertext = [
///     0xE4, 0xD9, 0x90, 0x64, 0xA6, 0xA6, 0x5F, 0x7E,
///     0x70, 0xDB, 0xF9, 0xDD, 0xE7, 0x0D, 0x6F, 0x6A,
///     0x0C, 0xEC, 0xDB, 0xAD, 0x01, 0xB4, 0xB1, 0xDE,
///     0xB4, 0x4A, 0xB8, 0xA0, 0xEA, 0x0E, 0x8F, 0x31
/// ];
/// let plaintext = key.decrypt(Some(iv), &ciphertext).unwrap();
///
/// assert_eq!(&plaintext.as_slice()[..16], "THIS_IS_THE_DATA".as_bytes());
/// ```
Decrypts data using the symmetric key
The IV is not needed for [`ChainingMode::Ecb`], so `None` should be used
in this case.

For chaining modes needing an IV, `None` can be used and a default IV will be used.
This is not documented on Microsoft's website and is therefore not recommended.
Decrypts data using the symmetric key The IV is not needed for [ ` ChainingMode :: Ecb ` ] so ` None ` should be used in this case . For chaining modes needing an IV ` None ` can be used and a default IV will be used . This is not documented on Microsoft ' s website and is therefore not recommended .
pub fn decrypt(&self, iv: Option<&[u8]>, data: &[u8]) -> Result<Buffer> {
        let mut iv_copy = iv.map(|iv| Buffer::from(iv));
        let iv_ptr = iv_copy.as_mut().map_or(null_mut(), |iv| iv.as_mut_ptr());
        let iv_len = iv_copy.as_ref().map_or(0, |iv| iv.len() as ULONG);
        let mut plaintext_len = MaybeUninit::<ULONG>::uninit();
        unsafe {
            Error::check(BCryptDecrypt(
                self.handle.as_ptr(),
                data.as_ptr() as PUCHAR,
                data.len() as ULONG,
                null_mut(),
                iv_ptr,
                iv_len,
                null_mut(),
                0,
                plaintext_len.as_mut_ptr(),
                BCRYPT_BLOCK_PADDING,
            ))?;
            let mut output = Buffer::new(plaintext_len.assume_init() as usize);
            Error::check(BCryptDecrypt(
                self.handle.as_ptr(),
                data.as_ptr() as PUCHAR,
                data.len() as ULONG,
                null_mut(),
                iv_ptr,
                iv_len,
                output.as_mut_ptr(),
                output.len() as ULONG,
                plaintext_len.as_mut_ptr(),
                BCRYPT_BLOCK_PADDING,
            ))
            .map(|_| output)
        }
    }
pub fn decrypt ( & self , iv : Option < & [ u8 ] > , data : & [ u8 ] ) -> Result < Buffer > { let mut iv_copy = iv . map ( | iv | Buffer :: from ( iv ) ) ; let iv_ptr = iv_copy . as_mut ( ) . map_or ( null_mut ( ) , | iv | iv . as_mut_ptr ( ) ) ; let iv_len = iv_copy . as_ref ( ) . map_or ( 0 , | iv | iv . len ( ) as ULONG ) ; let mut plaintext_len = MaybeUninit :: < ULONG > :: uninit ( ) ; unsafe { Error :: check ( BCryptDecrypt ( self . handle . as_ptr ( ) , data . as_ptr ( ) as PUCHAR , data . len ( ) as ULONG , null_mut ( ) , iv_ptr , iv_len , null_mut ( ) , 0 , plaintext_len . as_mut_ptr ( ) , BCRYPT_BLOCK_PADDING , ) ) ? ; let mut output = Buffer :: new ( plaintext_len . assume_init ( ) as usize ) ; Error :: check ( BCryptDecrypt ( self . handle . as_ptr ( ) , data . as_ptr ( ) as PUCHAR , data . len ( ) as ULONG , null_mut ( ) , iv_ptr , iv_len , output . as_mut_ptr ( ) , output . len ( ) as ULONG , plaintext_len . as_mut_ptr ( ) , BCRYPT_BLOCK_PADDING , ) ) . map ( | _ | output ) } }
Decrypts data using the symmetric key
The IV is not needed for [`ChainingMode::Ecb`], so `None` should be used
in this case.
Decrypts data using the symmetric key The IV is not needed for [ ` ChainingMode :: Ecb ` ] so ` None ` should be used in this case .
&self
iv
Option<&[u8]>
data
&[u8]
&self
iv
Option<&[u8]>
data
&[u8]
examples
None
use win_crypto_ng::symmetric::{chainingmode, symmetricalgorithm, symmetricalgorithmid};
None
let algo = symmetricalgorithm::open(symmetricalgorithmid::aes, chainingmode::cbc).unwrap();
None