GenerateIV() public abstract method

public abstract GenerateIV ( ) : void
return void
コード例 #1
0
 private void initOther()
 {
     provider.Mode    = defaultMode;
     provider.Padding = defaultPadding;
     provider.GenerateIV();
     provider.GenerateKey();
 }
コード例 #2
0
ファイル: Secure.cs プロジェクト: andywhitfield/RunnersPal
        static Secure()
        {
            try
            {
                var secureSettings = MassiveDB.Current.FindSettings("Secure");
                algorithm = new RijndaelManaged();

                if (secureSettings.Count() != 2)
                {
                    MassiveDB.Current.RemoveDomainSettings("Secure");

                    algorithm.GenerateIV();
                    algorithm.GenerateKey();

                    MassiveDB.Current.InsertDomainSetting("Secure", "IV", Convert.ToBase64String(algorithm.IV));
                    MassiveDB.Current.InsertDomainSetting("Secure", "Key", Convert.ToBase64String(algorithm.Key));
                }
                else
                {
                    algorithm.IV = Convert.FromBase64String(secureSettings.Single(s => s.Identifier == "IV").SettingValue);
                    algorithm.Key = Convert.FromBase64String(secureSettings.Single(s => s.Identifier == "Key").SettingValue);
                }
            }
            catch (Exception ex)
            {
                algorithm = null;
                initException = ex;
            }
        }
コード例 #3
0
		public NetCryptoProviderBase(NetPeer peer, SymmetricAlgorithm algo)
			: base(peer)
		{
			m_algorithm = algo;
			m_algorithm.GenerateKey();
			m_algorithm.GenerateIV();
		}
コード例 #4
0
ファイル: cryptography.cs プロジェクト: elaverick/wincrypt
 public cryptography(bool IsConsole, bool oldExpansionMethod = false)
 {
     isConsole = IsConsole;
     oldFormatKeyExpansion = oldExpansionMethod;
     twoFish = new Twofish();
     twoFish.Mode = CipherMode.CBC;
     twoFish.GenerateIV();
     twoFish.GenerateKey();
 }
コード例 #5
0
ファイル: SymmetricMethod.cs プロジェクト: BaiMath/ForKids
 /// <summary>
 /// 获得初始向量IV
 /// </summary>
 /// <returns>初试向量IV</returns>
 private static byte[] GetLegalIV(SymmetricAlgorithm mobjCryptoService)
 {
     string sTemp = "A4ghj*Ghg7!rNIfb&95GUY86GfghUb#er57HBh(u%g6HJ($jhWk7&!hg4ui%$hjo";
     mobjCryptoService.GenerateIV();
     byte[] bytTemp = mobjCryptoService.IV;
     int IVLength = bytTemp.Length;
     if (sTemp.Length > IVLength)
         sTemp = sTemp.Substring(0, IVLength);
     else if (sTemp.Length < IVLength)
         sTemp = sTemp.PadRight(IVLength, ' ');
     return ASCIIEncoding.ASCII.GetBytes(sTemp);
 }
コード例 #6
0
ファイル: frmMain.cs プロジェクト: lockflatboy/AES-Builder
        public void Build(SymmetricAlgorithm algorithm)
        {
            if (algorithm == null)
                throw new ArgumentNullException("algorithm");

            using (algorithm)
            {
                algorithm.KeySize = CurrentKeySize;
                algorithm.BlockSize = CurrentBlockSize;
                algorithm.Mode = SelectedCipher;
                algorithm.Padding = SelectedPadding;

                algorithm.GenerateIV();
                algorithm.GenerateKey();

                textBoxIV.Text = Convert.ToBase64String(algorithm.IV);
                textBoxKey.Text = Convert.ToBase64String(algorithm.Key);
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: AlinaKapustina/nsudotnet
 static void EncryptorType(SymmetricAlgorithm sa, string file_output, string file_input)
 {
     sa.GenerateKey();
     sa.GenerateIV();
     ICryptoTransform transform = sa.CreateEncryptor(sa.Key, sa.IV);
     using (FileStream file = new FileStream(file_output, FileMode.Create, FileAccess.Write))
     {
        using( CryptoStream stream = new CryptoStream(file, transform, CryptoStreamMode.Write))
         using (FileStream input = new FileStream(file_input, FileMode.Open))
         {
             input.CopyTo(stream);
         }
         using (StreamWriter key = new StreamWriter("file.key.txt"))
         {
             string s = Convert.ToBase64String(sa.IV);
             key.WriteLine(s);
             s = Convert.ToBase64String(sa.Key);
             key.Write(s);
         }
     }
 }
コード例 #8
0
 public static byte[] EncryptString(string source, SymmetricAlgorithm algorithm)
 {
     byte[] buffer;
     algorithm.GenerateIV();
     algorithm.GenerateKey();
     using (MemoryStream stream = new MemoryStream(0x80))
     {
         using (new BinaryWriter(stream))
         {
             stream.Write(algorithm.IV, 0, algorithm.IV.Length);
             stream.Write(algorithm.Key, 0, algorithm.Key.Length);
             using (CryptoStream stream2 = new CryptoStream(stream, algorithm.CreateEncryptor(), CryptoStreamMode.Write))
             {
                 using (TextWriter writer2 = new StreamWriter(stream2))
                 {
                     writer2.Write(source);
                 }
             }
             buffer = stream.ToArray();
         }
     }
     return buffer;
 }
コード例 #9
0
ファイル: CryptoHelper.cs プロジェクト: Geminior/DeepConfig
        internal static byte[] Encrypt(SymmetricAlgorithm crypter, byte[] data, byte[] cryptoKey, byte[] authKey, byte[] clearTextPayload)
        {
            byte[] cipherText;

            //Get an IV
            crypter.GenerateIV();
            byte[] iv = crypter.IV;

            //Encrypt Data
            using (var encrypter = crypter.CreateEncryptor(cryptoKey, iv))
            using (var cipherStream = new MemoryStream())
            {
                using (var cryptoStream = new CryptoStream(cipherStream, encrypter, CryptoStreamMode.Write))
                {
                    cryptoStream.Write(data, 0, data.Length);
                    cryptoStream.FlushFinalBlock();
                }

                cipherText = cipherStream.ToArray();
            }

            //Assemble encrypted message and add authentication
            using (var hmac = new HMACSHA256(authKey))
            using (var encryptedStream = new MemoryStream())
            {
                using (var binaryWriter = new BinaryWriter(encryptedStream))
                {
                    //Add clear text data first
                    if (clearTextPayload != null)
                    {
                        binaryWriter.Write(clearTextPayload);
                    }

                    //The add the IV
                    binaryWriter.Write(iv);

                    //Write Ciphertext
                    binaryWriter.Write(cipherText);

                    //Authenticate all data
                    var tag = hmac.ComputeHash(encryptedStream.ToArray());

                    //Append tag
                    binaryWriter.Write(tag);
                }

                return encryptedStream.ToArray();
            }
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: sancas/ProgramacionIII
 private static void GenerarIV(SymmetricAlgorithm algoritmo)
 {
     // Si haces lo siguiente se genera un nuevo IV
     algoritmo.GenerateIV();
     // sacamos el IV por consola
     Console.WriteLine("IV (Vector de inicialización): ");
     foreach (byte b in algoritmo.IV)
     {
         Console.Write("{0:X2} ", b);
     }
     Console.WriteLine("\nPulse una tecla para continuar…\n");
     Console.ReadKey();
 }
 private void SetKeyOnSymAlgorithm(SymmetricAlgorithm symAlgo, byte[] dKey)
 {
     try
     {
         if ((dKey.Length > 8) && (symAlgo is DESCryptoServiceProvider))
         {
             byte[] dst = new byte[8];
             Buffer.BlockCopy(dKey, 0, dst, 0, 8);
             symAlgo.Key = dst;
             DestroyByteArray(dst);
         }
         else
         {
             symAlgo.Key = dKey;
         }
         symAlgo.GenerateIV();
         symAlgo.IV = new byte[symAlgo.IV.Length];
     }
     catch (Exception exception)
     {
         throw new ConfigurationErrorsException(System.Web.SR.GetString("Bad_machine_key", new object[] { exception.Message }), base.ElementInformation.Properties["decryptionKey"].Source, base.ElementInformation.Properties["decryptionKey"].LineNumber);
     }
 }
コード例 #12
0
ファイル: Cryptographer.cs プロジェクト: netcasewqs/nlite
        private byte[] GetLegalIV(SymmetricAlgorithm cryptoObj)
        {
            if (string.IsNullOrEmpty(iv))
                return null;//iv = DEFAULT_IV;

            string sTemp = iv;
            cryptoObj.GenerateIV();
            byte[] bytTemp = cryptoObj.IV;
            int IVLength = bytTemp.Length;
            if (sTemp.Length > IVLength)
                sTemp = sTemp.Substring(0, IVLength);
            else if (sTemp.Length < IVLength)
                sTemp = sTemp.PadRight(IVLength, ' ');
            return ASCIIEncoding.ASCII.GetBytes(sTemp);
        }
コード例 #13
0
 private void SetKeyOnSymAlgorithm(SymmetricAlgorithm symAlgo, byte[] dKey)
 {
     try {
         if (dKey.Length > 8 && symAlgo is DESCryptoServiceProvider) {
             byte[] bTemp = new byte[8];
             Buffer.BlockCopy(dKey, 0, bTemp, 0, 8);
             symAlgo.Key = bTemp;
             DestroyByteArray(bTemp);
         } else {
             symAlgo.Key = dKey;
         }
         symAlgo.GenerateIV();
         symAlgo.IV = new byte[symAlgo.IV.Length];
     } catch (Exception e) {
         throw new ConfigurationErrorsException(SR.GetString(SR.Bad_machine_key, e.Message), ElementInformation.Properties["decryptionKey"].Source, ElementInformation.Properties["decryptionKey"].LineNumber);
     }
 }
コード例 #14
0
ファイル: CryptographyManager.cs プロジェクト: Oman/Maleos
 private byte[] GetLegalIV(SymmetricAlgorithm mobjCryptoService)
 {
     string sTemp = _defaultLegalIV;
     mobjCryptoService.GenerateIV();
     byte[] bytTemp = mobjCryptoService.IV;
     int IVLength = bytTemp.Length;
     if (sTemp.Length > IVLength)
         sTemp = sTemp.Substring(0, IVLength);
     else if (sTemp.Length < IVLength)
         sTemp = sTemp.PadRight(IVLength, ' ');
     return ASCIIEncoding.ASCII.GetBytes(sTemp);
 }
コード例 #15
0
ファイル: SecureQueryString.cs プロジェクト: nehawadhwa/ccweb
 /// <summary>
 /// Creates an instance with a specified algorithm and key.
 /// </summary>
 /// <param name="algorithm">The algorithm to use for cryptographic functions.</param>
 /// <param name="key">The key to use for this algorithm.</param>
 public SymmetricAlgorithmProvider(SymmetricAlgorithm algorithm, byte[] key)
 {
     this.algorithm = algorithm;
     algorithm.Key = key;
     algorithm.GenerateIV();
     IVSize = algorithm.IV.Length;
 }
コード例 #16
0
        /// <summary>
        /// Creates a random IV value appropriate for
        /// the encryption algorithm
        /// </summary>
        /// <param name="encryptionAlgorithm">Instance of SymmetricAlgorithm used to create the IV</param>
        /// <returns>Base64 encoded byte array containing the IV value</returns>
        protected static string CreateBase64IV(SymmetricAlgorithm encryptionAlgorithm)
        {
            byte[] iv = null;
            try
            {
              encryptionAlgorithm.GenerateIV();
              iv = encryptionAlgorithm.IV;

            }
            finally
            {
              encryptionAlgorithm.Clear();
              ((IDisposable)encryptionAlgorithm).Dispose();
            }
            return Convert.ToBase64String(iv);
        }
コード例 #17
0
ファイル: SecurityEx.cs プロジェクト: BclEx/AdamsyncEx
 /// <summary>
 /// Generates the symmetric iv.
 /// </summary>
 /// <param name="algorithm">The algorithm.</param>
 /// <returns></returns>
 public static byte[] GenerateSymmetricIv(SymmetricAlgorithm algorithm)
 {
     algorithm.GenerateIV();
     return algorithm.IV;
 }
コード例 #18
0
 public override void GenerateIV()
 {
     m_impl.GenerateIV();
 }
コード例 #19
0
ファイル: HashCryptTests.cs プロジェクト: yuanfei05/vita
 private void GenerateKey(SymmetricAlgorithm alg)
 {
     alg.GenerateKey();
       alg.GenerateIV();
       Debug.WriteLine("Algorithm: " + alg.GetType().Name.PadRight(30) + " keySize(bits): " + alg.KeySize + " key: " + HexUtil.ByteArrayToHex(alg.Key));
 }
コード例 #20
0
ファイル: InjectDLL.cs プロジェクト: tqtam/LUANVAN
 public Main(
      RemoteHooking.IContext InContext,
      String InChannelName)
 {
     // connect to host...
     Interface = RemoteHooking.IpcConnectClient<FileMonInterface>(InChannelName);
     myChannelName = InChannelName;
     aes = new AesCryptoServiceProvider();
     dataIgnition = new byte[MAX_BLOCK_SIZE];
     for (int i = 0; i < MAX_BLOCK_SIZE; i++)
     {
         dataIgnition[i] = (byte)i;
     }
     dataToEncrypt = new byte[MAX_BLOCK_SIZE];
     OutputDebugString(Encoding.ASCII.GetString(dataIgnition));
     Rfc2898DeriveBytes key = new Rfc2898DeriveBytes(Password, Encoding.ASCII.GetBytes(Salt));
     aes.Key = key.GetBytes(aes.KeySize / 8);
     aes.Padding = PaddingMode.Zeros;
     byte[] IV = Interface.GetIV();
     if (IV == null)
     {
         aes.GenerateIV();
         Interface.SaveIV(aes.IV);
     }
     aes.Mode = CipherMode.CFB;
     Interface.Ping();
 }
コード例 #21
0
ファイル: EncryptManager.cs プロジェクト: wolfweb/Ww
        private void SetEncryptor() {
            switch (_mbytEncryptionType) {
                case SymmetricEncryptType.Des:
                    _mCsp = new DESCryptoServiceProvider();
                    break;

                case SymmetricEncryptType.Rc2:
                    _mCsp = new RC2CryptoServiceProvider();
                    break;

                case SymmetricEncryptType.Rijndael:
                    _mCsp = new RijndaelManaged();
                    break;

                case SymmetricEncryptType.TripleDes:
                    _mCsp = new TripleDESCryptoServiceProvider();
                    break;
            }
            _mCsp.GenerateKey();
            _mCsp.GenerateIV();
        }