public void ShouldDecryptSecretWhenLoading() { var keeper = new SecretKeeper("KEY"); var instance = TomlConfig .FromString($"Password = \"{keeper.Encrypt("42")}\"") .WithMasterKey("KEY") .Read <ConfigWithSecret>(); Check.That(instance.Password).IsEqualTo("42"); }
public void ShouldDoSecretRoundTrip() { var sc = new SecretKeeper(Security.GenerateKeyAsString()); var iLovePink = "I love pink!"; var cypher = sc.Encrypt(iLovePink); Check.That(sc.Decrypt(cypher)) .IsEqualTo(iLovePink); }
public void ShouldDecryptSecrets() { var key = Security.GenerateKeyAsString(); var secretKeeper = new SecretKeeper(key); var secret = "MyVerySecretPassword"; var instance = TomlConfig .FromString($"MyPassword = \"{secretKeeper.Encrypt(secret)}\"") .WithMasterKey(key) .Read <ConfigWithSecret>(); Check.That(instance.MyPassword) .IsEqualTo(secret); }
private bool EncryptValue(string value, out string cypherValue) { var secretKeeper = new SecretKeeper(masterKey); if (secretKeeper.IsValidCypher(value, out var thumb, out _)) { secretKeeper.AssertSecretThumbnail(thumb); cypherValue = null; return(false); } cypherValue = secretKeeper.Encrypt(value); return(true); }
public void ShouldFailWithExceptionIfMasterKeyIsNotMatched() { var sc = new SecretKeeper(Security.GenerateKeyAsString()); var iLovePink = "I love pink!"; var cypher = sc.Encrypt(iLovePink); sc = new SecretKeeper(Security.GenerateKeyAsString()); Check.ThatCode(() => sc.Decrypt(cypher)) .Throws <TomlConfigurationException>() .AndWhichMessage() .Contains("thumbnail"); }