/// <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(); }
public static CipherPairFile CreateRandomKeyFile(string filePath) { var cp = SymmetricCipherPair.AutogenerateRijndael(); CipherPairFile kf = new CipherPairFile(filePath, cp); kf = new CipherPairFile(filePath); return(kf); }
/// <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(); }
/// <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(); }
public KeyChainItem(string id, SymmetricCipherPair keyAndEntropy) { Condition.Requires(id).IsNotNullOrEmpty(); Condition.Requires(keyAndEntropy).IsNotNull(); this.Id = id; this.KeyAndEntropy = keyAndEntropy; }
/// <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); }
/// <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(); }
/// <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); }
public static Func <string, string> GetSymmetricDecodingStrategy(this SymmetricCipherPair cp) { return((x) => { return cp.Decrypt(x); }); }
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; }
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; }
/// <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; }