Ejemplo n.º 1
0
    /// <summary>
    /// Decrypts the secret and fills into this secret exchange instance.
    /// </summary>
    /// <param name="secretEncrypted">The new secret encrypted.</param>
    /// <param name="ignoreFormatIfNoCrypto">true if ignore format when no crypto set; otherwise, false.</param>
    /// <param name="padding">The optional padding mode for decryption.</param>
    public void DecryptSecret(string secretEncrypted, bool ignoreFormatIfNoCrypto, RSAEncryptionPadding padding = null)
    {
        if (Secret != null)
        {
            Secret.Dispose();
        }
        if (string.IsNullOrWhiteSpace(secretEncrypted))
        {
            Secret = null;
            return;
        }

        var rsa = crypto;

        if (rsa == null)
        {
            if (!ignoreFormatIfNoCrypto && SecretFormatBeforeDecrypt != null)
            {
                secretEncrypted = SecretFormatBeforeDecrypt(secretEncrypted, false);
            }
            Secret = secretEncrypted.ToSecure();
            return;
        }

        var plain = rsa.Decrypt(Convert.FromBase64String(secretEncrypted), padding ?? RSAEncryptionPadding.Pkcs1);

        Secret = SecretFormatBeforeDecrypt != null?SecretFormatBeforeDecrypt(Encoding.UTF8.GetString(plain), true).ToSecure() : Encoding.UTF8.GetString(plain).ToSecure();
    }
Ejemplo n.º 2
0
 public void Hide()
 {
     try
     {
         if (IsShown)
         {
             IsShown = false;
             if (CurrentPattern != null)
             {
                 CurrentPattern.Dispose();
                 CurrentPattern = null;
             }
             if (Secret != null)
             {
                 Secret.Dispose();
                 Secret = null;
             }
             if (CurrentBrush != null)
             {
                 CurrentBrush.Dispose();
                 CurrentBrush = null;
             }
             Layers.Unloaded();
             Tools.Unloaded();
         }
     }
     catch (System.Exception e) { Logger.Log(Logger.Level.ERROR, "[PatternEditor] Error while hiding: " + e.ToString()); }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Sets a new secret.
 /// </summary>
 /// <param name="secret">The new secret to set.</param>
 public void SetSecret(SecureString secret)
 {
     if (Secret != null)
     {
         Secret.Dispose();
     }
     Secret = secret?.Copy();
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Clears the secret.
 /// </summary>
 public void ClearSecret()
 {
     if (Secret != null)
     {
         Secret.Dispose();
     }
     Secret = null;
 }
Ejemplo n.º 5
0
        public void SecretIndicatesObjectIsDisposedWhenDisposed()
        {
            var secret = new Secret(new byte[] { });

            secret.IsDisposed.Should().BeFalse();
            secret.Dispose();
            secret.IsDisposed.Should().BeTrue();
        }
Ejemplo n.º 6
0
        public void SecretThrowsObjectDisposedExceptionWhenAlreadyDisposed()
        {
            var secret = new Secret(new byte[] { });

            secret.Dispose();
            Action test = () => secret.UseAsBytes(b => { });

            test.ShouldThrow <ObjectDisposedException>();
        }
Ejemplo n.º 7
0
    /// <summary>
    /// Sets a new secret.
    /// </summary>
    /// <param name="secret">The new secret to set.</param>
    public void SetSecret(string secret)
    {
        if (Secret != null)
        {
            Secret.Dispose();
        }
        if (string.IsNullOrWhiteSpace(secret))
        {
            Secret = null;
            return;
        }

        Secret = secret.ToSecure();
    }
Ejemplo n.º 8
0
 /// <summary>
 /// Releases the unmanaged resources used by this instance and optionally releases the managed resources.
 /// </summary>
 /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
 protected virtual void Dispose(bool disposing)
 {
     if (!disposing)
     {
         return;
     }
     if (crypto != null && needDisposeCrypto)
     {
         crypto.Dispose();
     }
     if (Secret != null)
     {
         Secret.Dispose();
     }
     crypto = null;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Dispose
 /// </summary>
 public void Dispose()
 {
     Key?.Dispose();
     Secret?.Dispose();
     PrivateKey?.Dispose();
 }
 public void Dispose()
 {
     _keyDerivationKey.Dispose();
 }