Click here to Skip to main content
15,890,579 members
Home / Discussions / C#
   

C#

 
GeneralRe: Replacing backslahes in a string Pin
Saksida Bojan24-Dec-09 3:55
Saksida Bojan24-Dec-09 3:55 
Questionpassing parameters from crystal report to windows form Pin
Nitin S24-Dec-09 1:11
professionalNitin S24-Dec-09 1:11 
Generalcoding of IPsec functionality Pin
3bood.ghzawi24-Dec-09 0:00
3bood.ghzawi24-Dec-09 0:00 
QuestionCREATE DATABASE permission denied in database 'master' Pin
haleemasher23-Dec-09 19:39
haleemasher23-Dec-09 19:39 
AnswerRe: CREATE DATABASE permission denied in database 'master' Pin
Russ-T23-Dec-09 20:24
Russ-T23-Dec-09 20:24 
Questiondraw rich text in a custom control Pin
Duong Tien Nam23-Dec-09 16:11
Duong Tien Nam23-Dec-09 16:11 
AnswerRe: draw rich text in a custom control Pin
Jimmanuel24-Dec-09 2:25
Jimmanuel24-Dec-09 2:25 
QuestionC# TripleDES and Perl CPAN:Crypt Pin
draskosaric23-Dec-09 15:28
draskosaric23-Dec-09 15:28 
Hi,

I am trying to encrypt data with TripleDES algorithm using given key and given iv in c#, so I can get (correct) results that Perl code provides, but unfortunately I am failing in my attemps. Does anyone know what I am doing wrong?

Thanks in advance,
D

Here are sources:

Encryption in C#

<br />
public void encrypt() {<br />
string keyS = "W-3lee7#AA345ll812345678";<br />
            string ivS = "00000000";<br />
            string testText = "20091217140739-1"<br />
<br />
            byte[] key = new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(keyS));<br />
            byte[] iv = Encoding.UTF8.GetBytes(ivS);<br />
            byte[] data = Encoding.UTF8.GetBytes(testText);<br />
            byte[] enc = new byte[0];<br />
            byte[] dec = new byte[0];<br />
            TripleDES tdes = TripleDES.Create();<br />
            tdes.IV = iv;<br />
            tdes.Key = key;<br />
            tdes.Mode = CipherMode.CBC;<br />
            tdes.Padding = PaddingMode.PKCS7;<br />
            ICryptoTransform ict = tdes.CreateEncryptor();<br />
            enc = ict.TransformFinalBlock(data, 0, data.Length);<br />
            return BytesToHex(enc);<br />
}<br />
public string BytesToHex(byte[] bytes)<br />
        {<br />
            StringBuilder hexString = new StringBuilder(bytes.Length);<br />
            for (int i = 0; i < bytes.Length; i++)<br />
            {<br />
                hexString.Append(bytes[i].ToString("X2"));<br />
            }<br />
            return hexString.ToString();<br />
        }<br />


Perl code:
<br />
#!/usr/bin/perl<br />
<br />
use strict;<br />
use warnings;<br />
use Crypt::CBC;<br />
<br />
my $key = "W-3lee7#AA345ll812345678";<br />
<br />
my $cbc = Crypt::CBC->new(<br />
    -key => $key,<br />
    -header => 'none',<br />
    -iv => '00000000',<br />
    -cipher => 'DES_EDE3',<br />
);<br />
<br />
<br />
my $plaintext = "20091217140739-1";<br />
print "plaintext: " . $plaintext . "\n\n";<br />
<br />
my $encrypted = join('',unpack('H*',$cbc->encrypt($plaintext)));<br />
print "encrypted: " . $encrypted . "\n\n";<br />
<br />
my $decrypted = $cbc->decrypt(pack'H*',$encrypted);<br />
print "decrypted: " . $decrypted . "\n\n";<br />
<br />
<br />
1;<br />

AnswerRe: C# TripleDES and Perl CPAN:Crypt Pin
Garth J Lancaster23-Dec-09 17:01
professionalGarth J Lancaster23-Dec-09 17:01 
GeneralRe: C# TripleDES and Perl CPAN:Crypt Pin
draskosaric24-Dec-09 20:59
draskosaric24-Dec-09 20:59 
QuestionC# Creating a class and assigning properties to it. Pin
Darrall23-Dec-09 14:01
Darrall23-Dec-09 14:01 
AnswerRe: C# Creating a class and assigning properties to it. Pin
Luc Pattyn23-Dec-09 15:00
sitebuilderLuc Pattyn23-Dec-09 15:00 
GeneralRe: C# Creating a class and assigning properties to it. Pin
Darrall23-Dec-09 15:49
Darrall23-Dec-09 15:49 
GeneralRe: C# Creating a class and assigning properties to it. Pin
Luc Pattyn23-Dec-09 16:06
sitebuilderLuc Pattyn23-Dec-09 16:06 
GeneralRe: C# Creating a class and assigning properties to it. Pin
Darrall24-Dec-09 4:26
Darrall24-Dec-09 4:26 
AnswerRe: C# Creating a class and assigning properties to it. Pin
#realJSOP23-Dec-09 21:56
mve#realJSOP23-Dec-09 21:56 
GeneralRe: C# Creating a class and assigning properties to it. Pin
Darrall24-Dec-09 4:52
Darrall24-Dec-09 4:52 
AnswerRe: C# Creating a class and assigning properties to it. Pin
Richard MacCutchan23-Dec-09 22:28
mveRichard MacCutchan23-Dec-09 22:28 
GeneralRe: C# Creating a class and assigning properties to it. Pin
Darrall24-Dec-09 4:59
Darrall24-Dec-09 4:59 
AnswerRe: C# Creating a class and assigning properties to it. Pin
hamed-vojdani24-Dec-09 5:27
hamed-vojdani24-Dec-09 5:27 
GeneralRe: C# Creating a class and assigning properties to it. Pin
Darrall24-Dec-09 5:39
Darrall24-Dec-09 5:39 
QuestionCondense a list Pin
o m n i23-Dec-09 11:57
o m n i23-Dec-09 11:57 
AnswerRe: Condense a list Pin
Luc Pattyn23-Dec-09 12:07
sitebuilderLuc Pattyn23-Dec-09 12:07 
GeneralRe: Condense a list Pin
o m n i23-Dec-09 12:32
o m n i23-Dec-09 12:32 
QuestionGeneral issue: When application doesn't have focus, and you click a button on it, it doesn't register.... Pin
sherifffruitfly23-Dec-09 11:03
sherifffruitfly23-Dec-09 11:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.