private static char[] EncryptPassword(byte[] plaintext, byte[] publicKey) { try { byte[] ciphertext = SealedPublicKeyBox.Create(plaintext, publicKey); return(Convert.ToBase64String(ciphertext).ToCharArray()); } catch (Exception ex) when(ExceptionFilters.PasswordSharingExceptions(ex)) { Logging.LogException(ex.ToString(), Logging.Severity.Low); GetErrorMessage(ex); return(Array.Empty <char>()); } }
private static char[] DecryptPassword(byte[] ciphertext, byte[] privateKey) { try { using var keyPair = PublicKeyBox.GenerateKeyPair(privateKey); byte[] plaintext = SealedPublicKeyBox.Open(ciphertext, keyPair); return(Encoding.UTF8.GetChars(plaintext)); } catch (Exception ex) when(ExceptionFilters.PasswordSharingExceptions(ex)) { Logging.LogException(ex.ToString(), Logging.Severity.Low); GetErrorMessage(ex); return(Array.Empty <char>()); } }