예제 #1
0
 public static char[] ConvertUserInput(bool encryption, char[] base64Key, char[] password)
 {
     try
     {
         NullChecks.CharArray(base64Key);
         NullChecks.CharArray(password);
         char[] message;
         byte[] key = Convert.FromBase64CharArray(base64Key, 0, base64Key.Length);
         if (encryption == true)
         {
             byte[] plaintext = Encoding.UTF8.GetBytes(password);
             message = EncryptPassword(plaintext, key);
             Utilities.ZeroArray(plaintext);
         }
         else
         {
             byte[] ciphertext = Convert.FromBase64CharArray(password, 0, password.Length);
             message = DecryptPassword(ciphertext, key);
             Utilities.ZeroArray(ciphertext);
         }
         Utilities.ZeroArray(key);
         return(message);
     }
     catch (Exception ex) when(ex is FormatException || ex is EncoderFallbackException)
     {
         DisplayMessage.ErrorMessageBox(ex.GetType().Name, "Invalid key or password format.");
         return(Array.Empty <char>());
     }
 }