PDA

View Full Version : سوال: مشکل در encrypt فایل



minaalamshahi
سه شنبه 12 شهریور 1392, 14:43 عصر
سلام

من برای encrypt فایل با مشکل زیر روبرو میشم
Specified key is not a valid size for this algorithm

کدی که استفاده می کنم:




public void EncryptFile(string password1,string inputFile, string outputFile)
{

try
{
string password = @"myKey123"+password1; // Your Key Here

UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);

string cryptFile = outputFile;
FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);

RijndaelManaged RMCrypto = new RijndaelManaged();

CryptoStream cs = new CryptoStream(fsCrypt,
RMCrypto.CreateEncryptor(key, key),
CryptoStreamMode.Write);

FileStream fsIn = new FileStream(inputFile, FileMode.Open);

int data;
while ((data = fsIn.ReadByte()) != -1)
cs.WriteByte((byte)data);


fsIn.Close();
cs.Close();
fsCrypt.Close();
}
catch
{
//MessageBox.Show("Encryption failed!", "Error");
}
}

General-Xenon
سه شنبه 12 شهریور 1392, 23:58 عصر
سلام

من برای encrypt فایل با مشکل زیر روبرو میشم
Specified key is not a valid size for this algorithm

کدی که استفاده می کنم:




public void EncryptFile(string password1,string inputFile, string outputFile)
{

try
{
string password = @"myKey123"+password1; // Your Key Here

UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);

string cryptFile = outputFile;
FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);

RijndaelManaged RMCrypto = new RijndaelManaged();

CryptoStream cs = new CryptoStream(fsCrypt,
RMCrypto.CreateEncryptor(key, key),
CryptoStreamMode.Write);

FileStream fsIn = new FileStream(inputFile, FileMode.Open);

int data;
while ((data = fsIn.ReadByte()) != -1)
cs.WriteByte((byte)data);


fsIn.Close();
cs.Close();
fsCrypt.Close();
}
catch
{
//MessageBox.Show("Encryption failed!", "Error");
}
}


سلام . میگه این کلیدی که شما در نظر گرفتی مناسب این الگوریتم نیست .... را های دیگه ای هم برای Encrypt فیال هست ..
بلدی که یک عبارت رو Encrypt کنی ؟...
// مقدار فایلی که میخوای تبدیل کنی
byte[] FileByte = null; //
string Content = System.Text.Encoding.ASCII.GetString(FileByte);
// حالا این فیالی که تبدیل به متن شد رو Encrypt کن
// string encryptedData = ENCRYPT(Content);
string encryptedData = "kufg8o283g28o7fg287g827o3gf2783gf2378ort"; // < مثال
byte[] FileContent = System.Text.Encoding.ASCII.GetBytes(encryptedData) ;


در نهایت هم Save کن این Byte[] رو...
موفق باشی

صادق صدقی
شنبه 20 مهر 1392, 18:26 عصر
سلام

چرا من وقتی فایل رو اینکریپت می کنم همه چی درسته فقط فایل های آفیس مثه docx یا ... درست بر نمی گرده

محتویات بر می گرده اما نمی دونم چه کار می کنه که میگه فایلت مشکل داره
من موزیک ، txt pdf و .... رو روش کار کردم درست بود فقط همین منو خیلی اذیت کرده