Esempio n. 1
0
 /// <summary>
 /// loads the file and hydrates the cipher pair. expects a json serialized value
 /// </summary>
 private void Load()
 {
     var secureData = this.LockedFile.Read();
     var data = SecureStringUtil.ToInsecureString(secureData);
     this.Pair = JsonSerializer.DeserializeFromString<SymmetricCipherPair>(data);
     Condition.Requires(this.Pair).IsNotNull();
 }
Esempio n. 2
0
        public static CipherPairFile CreateRandomKeyFile(string filePath)
        {
            var            cp = SymmetricCipherPair.AutogenerateRijndael();
            CipherPairFile kf = new CipherPairFile(filePath, cp);

            kf = new CipherPairFile(filePath);
            return(kf);
        }
Esempio n. 3
0
        /// <summary>
        /// loads the file and hydrates the cipher pair. expects a json serialized value
        /// </summary>
        private void Load()
        {
            var secureData = this.LockedFile.Read();
            var data       = SecureStringUtil.ToInsecureString(secureData);

            this.Pair = JsonSerializer.DeserializeFromString <SymmetricCipherPair>(data);
            Condition.Requires(this.Pair).IsNotNull();
        }
Esempio n. 4
0
        /// <summary>
        /// this will write the cipher pair (json serialized) to file
        /// </summary>
        /// <param name="filePath"></param>
        public CipherPairFile(string filePath, SymmetricCipherPair pair)
            : base()
        {
            Condition.Requires(pair).IsNotNull();
            this.LockedFile = new LockedFile(filePath);

            this.Save();
        }
Esempio n. 5
0
        public KeyChainItem(string id, SymmetricCipherPair keyAndEntropy)
        {
            Condition.Requires(id).IsNotNullOrEmpty();
            Condition.Requires(keyAndEntropy).IsNotNull();

            this.Id            = id;
            this.KeyAndEntropy = keyAndEntropy;
        }
Esempio n. 6
0
        /// <summary>
        /// generates a new key of the provided size, and stores it at the given id
        /// </summary>
        /// <param name="id"></param>
        /// <param name="byteSize"></param>
        /// <returns></returns>
        public KeyChainItem AddNewRandomKey(string id)
        {
            KeyChainItem returnValue = new KeyChainItem(id, SymmetricCipherPair.AutogenerateRijndael());

            this.KeyStore.SaveItem(returnValue);

            return(returnValue);
        }
Esempio n. 7
0
        /// <summary>
        /// this will write the cipher pair (json serialized) to file
        /// </summary>
        /// <param name="filePath"></param>
        public CipherPairFile(string filePath, SymmetricCipherPair pair)
            : base()
        {
            Condition.Requires(pair).IsNotNull();
            this.LockedFile = new LockedFile(filePath);

            this.Save();
        }
Esempio n. 8
0
        /// <summary>
        /// given a symmetric crypto alg and some seed data, generates a key and IV
        /// </summary>
        /// <param name="algorithm"></param>
        /// <param name="password"></param>
        /// <param name="salt"></param>
        /// <returns></returns>
        public static SymmetricCipherPair GenerateKeyIV(SymmetricAlgorithm algorithm, string password, string salt)
        {
            DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));

            byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
            byte[] rgbIV  = rgb.GetBytes(algorithm.BlockSize >> 3);

            SymmetricCipherPair cp = new SymmetricCipherPair(rgbKey, rgbIV, algorithm);

            return(cp);
        }
Esempio n. 9
0
 public static Func <string, string> GetSymmetricDecodingStrategy(this SymmetricCipherPair cp)
 {
     return((x) => { return cp.Decrypt(x); });
 }
Esempio n. 10
0
 public static EncryptedStringableDecoration Encrypt(this IStringable thing, SymmetricCipherPair cipherPair)
 {
     Condition.Requires(thing).IsNotNull();
     return(new EncryptedStringableDecoration(thing, cipherPair));
 }
Esempio n. 11
0
 public EncryptedStringableDecoration(IStringable decorated, SymmetricCipherPair cipherPair)
     : base(decorated)
 {
     Condition.Requires(cipherPair).IsNotNull();
     this.CipherPair = cipherPair;
 }
 public static EncryptedStringableDecoration Encrypt(this IStringable thing, SymmetricCipherPair cipherPair)
 {
     Condition.Requires(thing).IsNotNull();
     return new EncryptedStringableDecoration(thing, cipherPair);
 }
 public EncryptedStringableDecoration(IStringable decorated, SymmetricCipherPair cipherPair)
     : base(decorated)
 {
     Condition.Requires(cipherPair).IsNotNull();
     this.CipherPair = cipherPair;
 }
Esempio n. 14
0
        /// <summary>
        /// given a symmetric crypto alg and some seed data, generates a key and IV 
        /// </summary>
        /// <param name="algorithm"></param>
        /// <param name="password"></param>
        /// <param name="salt"></param>
        /// <returns></returns>
        public static SymmetricCipherPair GenerateKeyIV(SymmetricAlgorithm algorithm, string password, string salt)
        {
            DeriveBytes rgb = new Rfc2898DeriveBytes(password, Encoding.Unicode.GetBytes(salt));

            byte[] rgbKey = rgb.GetBytes(algorithm.KeySize >> 3);
            byte[] rgbIV = rgb.GetBytes(algorithm.BlockSize >> 3);

            SymmetricCipherPair cp = new SymmetricCipherPair(rgbKey, rgbIV, algorithm);
            return cp;
        }