오늘 내 앱용 GZipStream 지원을 추가 했으므로 여기에서 일부 코드를 공유 할 수 있습니다.
직렬화 :
using (Stream s = File.Create(PathName))
{
RijndaelManaged rm = new RijndaelManaged();
rm.Key = CryptoKey;
rm.IV = CryptoIV;
using (CryptoStream cs = new CryptoStream(s, rm.CreateEncryptor(), CryptoStreamMode.Write))
{
using (GZipStream gs = new GZipStream(cs, CompressionMode.Compress))
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(gs, _instance);
}
}
}
역 직렬화 :
using (Stream s = File.OpenRead(PathName))
{
RijndaelManaged rm = new RijndaelManaged();
rm.Key = CryptoKey;
rm.IV = CryptoIV;
using (CryptoStream cs = new CryptoStream(s, rm.CreateDecryptor(), CryptoStreamMode.Read))
{
using (GZipStream gs = new GZipStream(cs, CompressionMode.Decompress))
{
BinaryFormatter bf = new BinaryFormatter();
_instance = (Storage)bf.Deserialize(gs);
}
}
}
참고 : CryptoStream을 사용하는 경우, 때문에, 당신은 체인 (UN) 압축하는과 (드) 이쪽을 암호화 등 것이 좀 중요하다 암호화하기 전에 데이터에서 잡음이 생기기 전에 엔트로피를 잃고 싶을 것입니다.
감사합니다. 정말로 도움이되었습니다. 압축 해제 된 모양은 어떨까요? 이전에는 BinaryFormatter를 사용하지 않았습니다. –
내 코드에 쉽게 복사하고 붙여 넣을 수있게 해주셔서 감사합니다. 자주 형식을 지정하여 이제는 Google에서 쉽게 찾을 수있는 스 니펫입니다. +1 –