PDF 파일을 .xxx 파일로 암호화하는 PHP 프로그램이 있습니다.이 출력은이 .xxx 파일을 PDF 파일로 다시 해독하는 C# 프로그램에서 읽습니다.출력이 잘못되었습니다
내 문제는 C#으로 해독 된 파일을 열면 PDF 판독기가 파일이 손상되었다고 알립니다. PHP에서 일반 텍스트를 암호화하고 C#에서 해독하면 암호화 된 파일이 생깁니다. 문제가 PDF 파일에만 나타나거나 다른 말로 표현하면 BINARY 파일
모든 제안 사항이 표시됩니다.
참고 : PHP에서
- 내가 (패딩은 수동으로 이루어집니다) C#에서
- 내가 데이터
를 암호화하고 해독하는 것은 RijndaelManaged 클래스를 사용 Mcrypt 라이브러리 확장 Rijndael을 알고리즘 CBC PKCS7 패딩을 사용 편집 :
다음은 PHP에서 사용하는 암호화 방법입니다.
,function encrypt($key, $iv, $text) {
ini_set ('memory_limit', '-1');
$mcrypt_cipher = MCRYPT_RIJNDAEL_256;
$mcrypt_mode = MCRYPT_MODE_CBC;
$text=addpadding($text,mcrypt_get_block_size($mcrypt_cipher,'cbc'));
$encrypted = rtrim (mcrypt_encrypt ($mcrypt_cipher, $key, $text, $mcrypt_mode, $iv), "\0");
$encrypted = base64_encode ($encrypted);
return $encrypted;
}
그리고 여기에는 암호 해독 C#에서 방법 :
public static string DecryptString(string message, string KeyString, string IVString)
{
byte[] Key = Encoding.UTF8.GetBytes(KeyString);
byte[] IV = Encoding.UTF8.GetBytes(IVString);
string decrypted = null;
RijndaelManaged rj = new RijndaelManaged();
rj.BlockSize = 256;
rj.Key = Key;
rj.IV = IV;
rj.Mode = CipherMode.CBC;
rj.Padding = PaddingMode.PKCS7;
try
{
MemoryStream ms = new MemoryStream();
//Encoding enc = new UTF8Encoding();
byte[] messageBytes = Convert.FromBase64String(message);
using (CryptoStream cs = new CryptoStream(ms, rj.CreateDecryptor(Key, IV), CryptoStreamMode.Write))
{
//byte[] messageBytes = enc.GetBytes(message);
cs.Write(messageBytes, 0, messageBytes.Length);
cs.Close();
}
byte[] encoded = ms.ToArray();
decrypted = Encoding.UTF8.GetString(encoded);
ms.Close();
}
catch (Exception e)
{
MessageBox.Show("An error occurred:"+ e.Message);
}
finally
{
rj.Clear();
}
return decrypted;
}
여기에 내가 C 번호에 해독을 호출하는 방법 내가 출력 작성하는 방법 :
string Key = cryptography.MD5("X-Ware" + cryptography.MD5("123"));
string IV = cryptography.MD5("XWare");
string decrypted = cryptography.DecryptString(contents, Key, IV);
string outputFilename = cryptography.MD5(OFD.FileName) + ".tmp";
StreamWriter sw = new StreamWriter("C:\\Windows\\Temp\\" + outputFilename, false, Encoding.UTF8);
BinaryWriter bw = new BinaryWriter(sw.BaseStream, Encoding.UTF8);
//sw.Write(decrypted);
bw.Write(decrypted);
sw.Close();
bw.Close();
당신이 인코딩/디코딩을 어떻게 붙여 넣을 수 있습니다 사용 ? – greut
해독 된 파일의 파일 크기가 원래 파일 크기와 같습니까? –
Windows에서 나는 추정합니까? –