コード例 #1
0
        /// <summary>
        /// Decrypts a byte array
        /// </summary>
        /// <param name="Data">Data to be decrypted</param>
        /// <param name="Key">Password to decrypt with</param>
        /// <param name="Algorithm">Algorithm to use for decryption</param>
        /// <param name="InitialVector">Needs to be 16 ASCII characters long</param>
        /// <param name="KeySize">
        /// Can be 64 (DES only), 128 (AES), 192 (AES and Triple DES), or 256 (AES)
        /// </param>
        /// <returns>A decrypted byte array</returns>
        public byte[] Decrypt(byte[] Data, DeriveBytes Key,
                              string Algorithm     = "AES",
                              string InitialVector = "OFRna73m*aze01xY",
                              int KeySize          = 256)
        {
            Contract.Requires <NullReferenceException>(SymmetricAlgorithms != null, "SymmetricAlgorithms");
            ISymmetric Found = SymmetricAlgorithms.FirstOrDefault(x => x.CanHandle(Algorithm));

            if (Found == null)
            {
                throw new ArgumentException(Algorithm + " not found");
            }
            return(Found.Decrypt(Data, Key, Algorithm, InitialVector, KeySize));
        }
コード例 #2
0
        /// <summary>
        /// Decrypts a byte array
        /// </summary>
        /// <param name="Data">Data to be decrypted</param>
        /// <param name="Key">Password to decrypt with</param>
        /// <param name="Algorithm">Algorithm to use for decryption</param>
        /// <param name="Salt">Salt to decrypt with</param>
        /// <param name="HashAlgorithm">Can be either SHA1 or MD5</param>
        /// <param name="PasswordIterations">Number of iterations to do</param>
        /// <param name="InitialVector">Needs to be 16 ASCII characters long</param>
        /// <param name="KeySize">
        /// Can be 64 (DES only), 128 (AES), 192 (AES and Triple DES), or 256 (AES)
        /// </param>
        /// <returns>A decrypted byte array</returns>
        public byte[] Decrypt(byte[] Data, string Key,
                              string Algorithm,
                              string Salt            = "Kosher",
                              string HashAlgorithm   = "SHA1",
                              int PasswordIterations = 2,
                              string InitialVector   = "OFRna73m*aze01xY",
                              int KeySize            = 256)
        {
            Contract.Requires <NullReferenceException>(SymmetricAlgorithms != null, "SymmetricAlgorithms");
            ISymmetric Found = SymmetricAlgorithms.FirstOrDefault(x => x.CanHandle(Algorithm));

            if (Found == null)
            {
                throw new ArgumentException(Algorithm + " not found");
            }
            return(Found.Decrypt(Data, Key, Algorithm, Salt, HashAlgorithm, PasswordIterations, InitialVector, KeySize));
        }
コード例 #3
0
ファイル: SymmetricTests.cs プロジェクト: JaCraig/HashBrowns
        public void Decrypt(ISymmetric testObject, int keySize)
        {
            var Key = testObject.CreateKey();
            var IV  = testObject.CreateInitialVector();

            Assert.NotNull(testObject.Decrypt(
                               testObject.Encrypt(
                                   new byte[] { 0, 1, 2, 3, 4, 5 },
                                   (byte[])Key.Clone(),
                                   "Salt".ToByteArray(),
                                   HashingAlgorithms.SHA512,
                                   2,
                                   IV,
                                   keySize),
                               (byte[])Key.Clone(),
                               "Salt".ToByteArray(),
                               HashingAlgorithms.SHA512,
                               2,
                               IV,
                               keySize));
        }
コード例 #4
0
 public ResultCrypto Decrypt <T>(string cipherText) where T : SymmetricAlgorithm, new()
 {
     return(symmetric.Decrypt <T>(cipherText));
 }