public async Task CanEncryptAndDecryptStringsUsingRealEncrypter()
    {
        var secretRepository = Container.Resolve <ISecretRepository>();

        var encrypterSecret = new SecretStringEncrypterFunction();

        Assert.IsFalse(string.IsNullOrEmpty(encrypterSecret.Guid));
        var errorsAndInfos = new ErrorsAndInfos();
        var csLambda       = await secretRepository.GetAsync(encrypterSecret, errorsAndInfos);

        Assert.IsFalse(errorsAndInfos.AnyErrors(), errorsAndInfos.ErrorsToString());
        var secretEncrypterFunction = await secretRepository.CompileCsLambdaAsync <string, string>(csLambda);

        var decrypterSecret = new SecretStringDecrypterFunction();

        Assert.IsFalse(string.IsNullOrEmpty(decrypterSecret.Guid));
        csLambda = await secretRepository.GetAsync(decrypterSecret, errorsAndInfos);

        Assert.IsFalse(errorsAndInfos.AnyErrors(), errorsAndInfos.ErrorsToString());
        var secretDecrypterFunction = await secretRepository.CompileCsLambdaAsync <string, string>(csLambda);

        const string originalString = "Whatever you do not want to reveal, keep it secret (\\, € ✂ and ❤)!";

        var encryptedString = secretEncrypterFunction(originalString);

        Assert.AreNotEqual(originalString, encryptedString);

        var decryptedString = secretDecrypterFunction(encryptedString);

        Assert.AreEqual(originalString, decryptedString);
    }
예제 #2
0
    protected async Task LoadSecretsIfNecessaryAsync()
    {
        if (SecretEncrypterFunction != null)
        {
            return;
        }

        var encrypterSecret = new SecretStringEncrypterFunction();
        var errorsAndInfos  = new ErrorsAndInfos();
        var csLambda        = await SecretRepository.GetAsync(encrypterSecret, errorsAndInfos);

        SecretEncrypterFunction = await SecretRepository.CompileCsLambdaAsync <string, string>(csLambda);

        var decrypterSecret = new SecretStringDecrypterFunction();

        csLambda = await SecretRepository.GetAsync(decrypterSecret, errorsAndInfos);

        SecretDecrypterFunction = await SecretRepository.CompileCsLambdaAsync <string, string>(csLambda);

        if (!errorsAndInfos.AnyErrors())
        {
            return;
        }

        throw new Exception(errorsAndInfos.ErrorsToString());
    }
    public async Task CanEncryptAndDecryptStrings()
    {
        var secretRepository = Container.Resolve <ISecretRepository>();

        var encrypterSecret = new SecretStringEncrypterFunction();

        Assert.IsFalse(string.IsNullOrEmpty(encrypterSecret.Guid));
        var secretEncrypterFunction = await secretRepository.CompileCsLambdaAsync <string, string>(encrypterSecret.DefaultValue);

        var decrypterSecret = new SecretStringDecrypterFunction();

        Assert.IsFalse(string.IsNullOrEmpty(decrypterSecret.Guid));
        var secretDecrypterFunction = await secretRepository.CompileCsLambdaAsync <string, string>(decrypterSecret.DefaultValue);

        const string originalString  = "Whatever you do not want to reveal, keep it secret (\\, € ✂ and ❤)!";
        var          encryptedString = secretEncrypterFunction(originalString);

        Assert.AreNotEqual(originalString, encryptedString);
        var decryptedString = secretDecrypterFunction(encryptedString);

        Assert.AreEqual(originalString, decryptedString);
    }