PDFファイルがあります。エラーが発生した
以下のコードを使用して暗号化する場合:Length of the data to encrypt is invalid.
string inputFile = @"C:\sample.pdf";
string outputFile = @"C:\sample_enc.pdf";
try
{
using (RijndaelManaged aes = new RijndaelManaged())
{
byte[] key = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
byte[] iv = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
aes.Key = key;
aes.IV = iv;
aes.Mode = CipherMode.CFB;
aes.Padding = PaddingMode.None;
aes.KeySize = 128;
aes.BlockSize = 128;
using (FileStream fsCrypt = new FileStream(outputFile, FileMode.Create))
{
using (ICryptoTransform encryptor = aes.CreateEncryptor(key,iv))
{
using (CryptoStream cs = new CryptoStream(fsCrypt, encryptor, CryptoStreamMode.Write))
{
using (FileStream fsIn = new FileStream(inputFile, FileMode.Open))
{
int data;
while ((data = fsIn.ReadByte()) != -1)
{
cs.WriteByte((byte)data);
}
}
}
}
}
}
}
catch (Exception ex)
{
// Length of the data to encrypt is invalid.
Console.WriteLine(ex.Message);
}
とCipherMode.CBC
でPaddingMode.PKCS7
、エラーはありません。
しかし、私のクライアントのために、AES/CFB with No Paddingを使用してファイルを暗号化する必要があります。
ここで何が起こっているのか、何か考えはありますか?