Esempio n. 1
0
 private void Initialize()
 {
     if (Key.IsNullOrEmpty())
     {
         Key = ChoByte.ToString(_defaultKey);
     }
     if (Vector.IsNullOrEmpty())
     {
         Vector = ChoByte.ToString(_defaultVector);
     }
 }
        public bool Initialize(bool beforeFieldInit, object state)
        {
            if (beforeFieldInit)
            {
                return(false);
            }

            if (Key.IsNullOrEmpty())
            {
                Key = ChoByte.ToString(_defaultKey);
            }
            if (Vector.IsNullOrEmpty())
            {
                Vector = ChoByte.ToString(_defaultVector);
            }

            return(true);
        }
Esempio n. 3
0
        /// Encrypt some text and return an encrypted byte array.
        public string Encrypt(string text)
        {
            //Translates our text value into a byte array.
            Byte[] bytes = _encoding.GetBytes(text);

            //Used to stream the data in and out of the CryptoStream.
            using (MemoryStream memoryStream = new MemoryStream())
            {
                //Write the decrypted value to the encryption stream
                using (CryptoStream cs = new CryptoStream(memoryStream, _encryptTransform, CryptoStreamMode.Write))
                {
                    cs.Write(bytes, 0, bytes.Length);
                    cs.FlushFinalBlock();

                    //Read encrypted value back out of the stream
                    memoryStream.Position = 0;

                    byte[] encrypted = new byte[memoryStream.Length];
                    memoryStream.Read(encrypted, 0, encrypted.Length);

                    return(ChoByte.ToString(encrypted));
                }
            }
        }
Esempio n. 4
0
 public static string GenerateEncryptionVectorString()
 {
     return(ChoByte.ToString(GenerateEncryptionVector()));
 }
Esempio n. 5
0
 public static string GenerateEncryptionKeyString()
 {
     return(ChoByte.ToString(GenerateEncryptionKey()));
 }