Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

AES enkripcija i dekripcija

[es] :: .NET :: AES enkripcija i dekripcija

[ Pregleda: 1530 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

program3r
Ivan Ivić
student

Član broj: 164258
Poruke: 18
*.adsl.net.t-com.hr.



Profil

icon AES enkripcija i dekripcija09.01.2009. u 15:42 - pre 186 meseci
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ꑞ⊪뮠쭗ᤝꦈ鍹ions⃊Generic;
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겭이렮㿆폫ఠ敫韇璝洣我硑鬳箱㚰菏契袲'ဗ솂슧쐻= Cip⑝er.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
 
Odgovor na temu

[es] :: .NET :: AES enkripcija i dekripcija

[ Pregleda: 1530 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.