public static ICryptoTransform GetDecryptor(byte SymAlgo, byte[] IV, byte[] SessionKey) { if (!IsValidAlgoCode(SymAlgo)) { throw new NotImplementedException("Algorithm not implemented"); } int KeySize = SymmetricAlgorithmTypes.GetKeySize(SymAlgo); int BlockSizeBits = SymmetricAlgorithmTypes.GetBlockSize(SymAlgo); if (IV == null) { IV = new byte[BlockSizeBits / 8]; // Set to all zeros by default } RijndaelManaged aes = new RijndaelManaged { KeySize = KeySize, BlockSize = BlockSizeBits, FeedbackSize = BlockSizeBits, Key = SessionKey, IV = IV, Mode = CipherMode.CFB, Padding = PaddingMode.None }; return(aes.CreateDecryptor()); }
public byte[] GetKey(string Password) { int KeySize = SymmetricAlgorithmTypes.GetKeySize(SymAlgo); int DesiredBytes = (byte)(KeySize / 8); HashAlgorithm HashAlgo = HashAlgorithmTypes.GetHashAlgoManaged(HashAlgorithm); byte[] Key = GetSaltedIterated(HashAlgo, DesiredBytes, Salt, Encoding.ASCII.GetBytes(Password), ByteCount); return(Key); }