0

このコードを使用してテキストの入力と出力を指定するにはどうすればよいですか?ファイルを開いてその内容を読み取り(その方法を知っています)、このコードを使用して復号化する必要があります。

    public string DecryptUsernamePassword(string cipherText)
    {
        if (string.IsNullOrEmpty(cipherText))
        {
            return cipherText;
        }

        byte[] salt = new byte[]
        {
            (byte)0xc7,
            (byte)0x73,
            (byte)0x21,
            (byte)0x8c,
            (byte)0x7e,
            (byte)0xc8,
            (byte)0xee,
            (byte)0x99
        };

        PKCSKeyGenerator crypto = new PKCSKeyGenerator("PASSWORD HERE", salt, 20, 1);

        ICryptoTransform cryptoTransform = crypto.Decryptor;
        byte[] cipherBytes = System.Convert.FromBase64String(cipherText);
        byte[] clearBytes = cryptoTransform.TransformFinalBlock(cipherBytes, 0, cipherBytes.Length);
        return Encoding.UTF8.GetString(clearBytes);
    }

cipherTextは暗号化されたテキストであり、clearBytesは暗号化されていないバイトですが、入力と出力にC#形式のtextBoxを使用する必要があります。

textBox1.Text(入力)->バイト-> ^ above^文字列->バイト->textBox2.Text(出力)入力が暗号化されたテキストであり、出力が復号化されている限り、何でも機能します。文章。

4

1 に答える 1

0

あなたのコメントに基づいて、私がまだ質問を適切に理解していると仮定します。これを独自のクラスにします。

 public class UsernameDecryptor
 {
      public string Decrypt(string cipherText)
      {
           if (string.IsNullOrEmpty(cipherText))
                return cipherText;


           byte[] salt = new byte[]
           {
                (byte)0xc7,
                (byte)0x73,
                 (byte)0x21,
                (byte)0x8c,
                (byte)0x7e,
                (byte)0xc8,
                (byte)0xee,
                (byte)0x99
            };

            PKCSKeyGenerator crypto = new PKCSKeyGenerator("PASSWORD HERE", salt, 20, 1);

            ICryptoTransform cryptoTransform = crypto.Decryptor;
            byte[] cipherBytes = System.Convert.FromBase64String(cipherText);
            byte[] clearBytes = cryptoTransform.TransformFinalBlock(cipherBytes, 0, cipherBytes.Length);

            return Encoding.UTF8.GetString(clearBytes);
      }
 }

次に、ボタン ハンドラー内で次のようにします。

private void button1_Click (object sender, System.EventArgs e)
{
     UsernameDecryptor decryptor = new UsernameDecryptor();

     string result = decryptor.Decrypt(inputTextBox.Text);

     outputTextBox.Text = result;
}
于 2012-03-20T17:34:58.713 に答える