示例#1
0
 public void Encrypt(ISymmetric testObject, int keySize)
 {
     Assert.NotNull(testObject.Encrypt(
                        new byte[] { 0, 1, 2, 3, 4, 5 },
                        testObject.CreateKey(),
                        "Salt".ToByteArray(),
                        HashingAlgorithms.SHA512,
                        2,
                        testObject.CreateInitialVector(),
                        keySize));
 }
示例#2
0
        /// <summary>
        /// Encrypts a byte array
        /// </summary>
        /// <param name="Data">Data to be encrypted</param>
        /// <param name="Key">Password to encrypt with</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>
        /// <param name="Algorithm">Algorithm</param>
        /// <returns>An encrypted byte array</returns>
        public byte[] Encrypt(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.Encrypt(Data, Key, Algorithm, InitialVector, KeySize));
        }
示例#3
0
        /// <summary>
        /// Encrypts a byte array
        /// </summary>
        /// <param name="Data">Data to be encrypted</param>
        /// <param name="Key">Password to encrypt with</param>
        /// <param name="Salt">Salt to encrypt 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>
        /// <param name="Algorithm">Algorithm</param>
        /// <returns>An encrypted byte array</returns>
        public byte[] Encrypt(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.Encrypt(Data, Key, Algorithm, Salt, HashAlgorithm, PasswordIterations, InitialVector, KeySize));
        }
示例#4
0
        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));
        }
示例#5
0
 public ResultCrypto Encrypt <T>(string plaintText) where T : SymmetricAlgorithm, new()
 {
     return(symmetric.Encrypt <T>(plaintText));
 }