コード例 #1
0
        public static byte[] AESCrypto(CryptoOperation cryptoOperation, AesCryptoServiceProvider aes, byte[] message)
        {
            using (var memStream = new MemoryStream())
            {
                CryptoStream cryptoStream = null;

                if (cryptoOperation == CryptoOperation.ENCRYPT)
                {
                    cryptoStream = new CryptoStream(memStream, aes.CreateEncryptor(), CryptoStreamMode.Write);
                }
                else if (cryptoOperation == CryptoOperation.DECRYPT)
                {
                    cryptoStream = new CryptoStream(memStream, aes.CreateDecryptor(), CryptoStreamMode.Write);
                }

                if (cryptoStream == null)
                {
                    return(null);
                }

                cryptoStream.Write(message, 0, message.Length);
                cryptoStream.FlushFinalBlock();
                return(memStream.ToArray());
            }
        }
コード例 #2
0
ファイル: DESDemos.cs プロジェクト: dushtusozzy/C-
        public static byte[] DESCrypto(CryptoOperation cryptoOperation, byte[] IV, byte[] key, byte[] message)
        {
            using (var DES = new DESCryptoServiceProvider())
            {
                DES.IV      = IV;
                DES.Key     = key;
                DES.Mode    = CipherMode.CBC;
                DES.Padding = PaddingMode.PKCS7;


                using (var memStream = new MemoryStream())
                {
                    CryptoStream cryptoStream = null;

                    if (cryptoOperation == CryptoOperation.ENCRYPT)
                    {
                        cryptoStream = new CryptoStream(memStream, DES.CreateEncryptor(), CryptoStreamMode.Write);
                    }
                    else if (cryptoOperation == CryptoOperation.DECRYPT)
                    {
                        cryptoStream = new CryptoStream(memStream, DES.CreateDecryptor(), CryptoStreamMode.Write);
                    }

                    if (cryptoStream == null)
                    {
                        return(null);
                    }

                    cryptoStream.Write(message, 0, message.Length);
                    cryptoStream.FlushFinalBlock();
                    return(memStream.ToArray());
                }
            }
        }
コード例 #3
0
 /// <summary>
 /// Create and populate a result for an encryption with authentication algorithm.
 /// </summary>
 /// <param name="Identifier"></param>
 /// <param name="OID"></param>
 /// <param name="Integrity"></param>
 /// <param name="Data"></param>
 /// <param name="Key">Key data</param>
 /// <param name="IV">Initialization Vector</param>
 public CryptoData(CryptoAlgorithmID Identifier, string OID,
                 byte[] Integrity, byte[] Data, byte [] Key, byte []IV) {
     _Identifier = Identifier;
     _Integrity = Integrity;
     _Data = Data;
     _OID = OID;
     _Key = Key;
     _IV = IV;
     _CryptoOperation = CryptoOperation.Unknown;
     }
コード例 #4
0
 /// <summary>
 /// Create and populate a result for an encryption with authentication algorithm.
 /// </summary>
 /// <param name="Identifier"></param>
 /// <param name="OID"></param>
 /// <param name="Value"></param>
 /// <param name="Data"></param>
 public CryptoData(CryptoAlgorithmID Identifier, string OID,
                 byte[] Value, byte[] Data) {
     _Identifier = Identifier;
     _Integrity = Value;
     _Data = Data;
     _OID = OID;
     _Key = null;
     _IV = null;
     _CryptoOperation = CryptoOperation.Unknown;
     }