[ program3r @ 09.01.2009. 15:42 ] @
Pozdrav imam jedan problem sa aes enkripcijom i dekripcijom naime navedeni kod radi kad je upitanju manji text npr. Here is some text to encrypt no kad treba enkriptirati veci dokument dobijem nesto vako asdfdusing System; using Systemꑞ⊪뮠쭗ᤝꦈ鍹ionsGeneric; using System.Linq; using吖屔鬹㚨�䔫聓♖ext; using System.IO; using System.Seﺱ隺뢻ﶔ訛餦ﳥ稯rypto⚛raphy; namespace Digitalni_potpis { 멇�䖐妕횈뽿㊝촮⇈s AES⍹ { byte[] IV = new byte[16] { 0, 0, 0, 0, 0,ഢ⡱䫳핷첤롗鬒穣⒰ 0, 0, 0, 0, 0, 0, 0, 0 }; pub㸷ᅶ䙅鈭⠳傈욝ꞕ[]▀E⁘crypt(strin婦㸠줱ㆳ崦諘䖙Ⅺxt, byte[] Key) { RijndaelManaged Cipher �༦鰼躗㝎⓬묫肥䁤옟생睦킠naged⍳); Cipher.Key = Key; Cipher.IV =랛승渘㿦ꓩ쁮汉 ⌘ 認﵎あ��큦erⅶPadding = PaddingMode혙旚鉀濅頱᪥栿ퟝㄚ噳凂ґⓌㅏᇂ ⓚICr겭이렮㿆폫ఠ敫韇璝洣我硑鬳箱㚰菏契袲'ဗ솂슧쐻= Ciper.CreateEncryptor(Key, IV); MemoryStream mStream = new Memor뽕۬∃펬付夸鞉); 쩫 䭧ﳈꆮ삞ryptoSt₫eam csEncrypt = new CryptoStream꓀倰㴭扆㹺罂䕉툎, ₅ncryptor, CryptoStreaꢬ摞큀ϛ쏫ꅹﻸ⁂te⟈) { using (StreamWriꖞ匈㾔ޫ斵漵�捾crypt =╟new StreamWriter稾햞幌٨渲뚏❆t)) { swEց蛝꣫儦汀⒀缲rit⛢(pl⁜inText); navedeni kod pa ako netko vidi gresku bio bih zahvalan using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Security.Cryptography; namespace Digitalni_potpis { class AES { byte[] IV = new byte[16] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; public byte[] Encrypt(string plainText, byte[] Key) { RijndaelManaged Cipher = new RijndaelManaged(); Cipher.Key = Key; Cipher.IV = IV; Cipher.Padding = PaddingMode.Zeros; ICryptoTransform Encryptor = Cipher.CreateEncryptor(Key, IV); MemoryStream mStream = new MemoryStream(); CryptoStream cStream = new CryptoStream(mStream, Encryptor, CryptoStreamMode.Write); byte[] plainBytes = UnicodeEncoding.Unicode.GetBytes(plainText); cStream.Write(plainBytes, 0, plainBytes.Length); cStream.FlushFinalBlock(); return mStream.ToArray(); } public string Decrypt(byte[] cipherText, byte[] Key) { byte[] cipherBytes = cipherText; RijndaelManaged Cipher = new RijndaelManaged(); Cipher.Key = Key; Cipher.IV = IV; Cipher.Padding = PaddingMode.Zeros; ICryptoTransform Decryptor = Cipher.CreateDecryptor(Key, IV); MemoryStream ms = new MemoryStream(cipherBytes); CryptoStream cs = new CryptoStream(ms, Decryptor, CryptoStreamMode.Read); byte[] plainBytes = new byte[cipherBytes.Length]; cs.Read(plainBytes, 0, cipherBytes.Length); return UnicodeEncoding.Unicode.GetString(plainBytes); } } } Mislin da je u pitanju padding al radi samo sa Zeros za ostale javi gresku Padding is not valid and can't be removed Pozdrav |