/// <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(); }
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()); } }
/// <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(); }
/// <summary> /// Clears the secret. /// </summary> public void ClearSecret() { if (Secret != null) { Secret.Dispose(); } Secret = null; }
public void SecretIndicatesObjectIsDisposedWhenDisposed() { var secret = new Secret(new byte[] { }); secret.IsDisposed.Should().BeFalse(); secret.Dispose(); secret.IsDisposed.Should().BeTrue(); }
public void SecretThrowsObjectDisposedExceptionWhenAlreadyDisposed() { var secret = new Secret(new byte[] { }); secret.Dispose(); Action test = () => secret.UseAsBytes(b => { }); test.ShouldThrow <ObjectDisposedException>(); }
/// <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(); }
/// <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; }
/// <summary> /// Dispose /// </summary> public void Dispose() { Key?.Dispose(); Secret?.Dispose(); PrivateKey?.Dispose(); }
public void Dispose() { _keyDerivationKey.Dispose(); }