私はクライアント/サーバーアプリケーションを持っています。サーバーとクライアントの通信は暗号化されています。サーバーは暗号化されたメッセージをクライアントとクライアントの復号化メッセージに送信し、それを取得します。クライアントメッセージと同じです。大きなデータをクライアントに送信するか、クライアントが大きなデータをサーバーに送信すると、「復号するデータの長さが無効です」というエラーが表示されます。データの送信が小さい場合は問題ありません。データ長の暗号化または復号化に制限はありますか?ここで私の「解読するデータの長さが不正です」エラー
は私のコードです:
static byte[] Encrypt(byte[] plaintext, byte[] key, byte[] IV)
{
RijndaelManaged myRijndael = new RijndaelManaged();
myRijndael.Padding = PaddingMode.PKCS7;
ICryptoTransform encryptor = myRijndael.CreateEncryptor(key, IV);
MemoryStream msEncrypt = new MemoryStream();
CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);
csEncrypt.Write(plaintext, 0, plaintext.Length);
csEncrypt.FlushFinalBlock();
return msEncrypt.ToArray();
}
public static string Encrypt(string plainText, string password)
{
byte[] byteDizi = Encoding.Unicode.GetBytes(plaintext);
PasswordDeriveBytes pdb = new PasswordDeriveBytes(password,
new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,
0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
byte[] sifreliV = Encrypt(byteDizi,
pdb.GetBytes(32), pdb.GetBytes(16));
return Convert.ToBase64String(sifreliV);
}
// Dekriptolama bir parola ve IV kullanarak
static byte[] Decrypt(byte[] encryptedData,
byte[] Key, byte[] IV)
{
RijndaelManaged myRijndael = new RijndaelManaged();
myRijndael.Padding = PaddingMode.PKCS7;
ICryptoTransform decryptor = myRijndael.CreateDecryptor(Key, IV);
MemoryStream msDecrypt = new MemoryStream(encryptedData);
CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read);
byte[] fromEncrypt = new byte[encryptedData.Length];
csDecrypt.Read(fromEncrypt, 0, fromEncrypt.Length);
return fromEncrypt;
}
public static string Decrypt(string encryptedData, string password)
{
byte[] encryptedByte = Convert.FromBase64String(encryptedData);
PasswordDeriveBytes pdb = new PasswordDeriveBytes(password,
new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65,
0x64, 0x76, 0x65, 0x64, 0x65, 0x76});
byte[] DecryptedData = Decrypt(encryptedByte,
pdb.GetBytes(32), pdb.GetBytes(16));
return Encoding.Unicode.GetString(DecryptedData);
}
}
あなたの暗号化方法の中では、 'byte []'配列とBase64 'String'配列の長さを記録します。あなたの解読メソッドの中で、入ってくるBase64 'String'と結果の' byte [] '配列の長さの同様のレコードを作ります。これらは正しく一致しますか?特に大きなファイルの場合、問題が発生していると言います。 – rossum