Click here to Skip to main content
16,004,924 members
Home / Discussions / C#
   

C#

 
QuestionRe: Scroll Problem Pin
MHASSANF10-Mar-07 21:24
MHASSANF10-Mar-07 21:24 
AnswerRe: Scroll Problem Pin
sam#10-Mar-07 23:25
sam#10-Mar-07 23:25 
AnswerRe: Scroll Problem Pin
Dave Kreskowiak11-Mar-07 4:36
mveDave Kreskowiak11-Mar-07 4:36 
QuestionLoop Pin
shamsteady10-Mar-07 17:25
shamsteady10-Mar-07 17:25 
AnswerRe: Loop Pin
Guffa10-Mar-07 18:09
Guffa10-Mar-07 18:09 
GeneralRe: Loop Pin
shamsteady10-Mar-07 18:17
shamsteady10-Mar-07 18:17 
AnswerRe: Loop Pin
Christian Graus10-Mar-07 19:40
protectorChristian Graus10-Mar-07 19:40 
QuestionDES Encryption Pin
Ravun10-Mar-07 16:47
Ravun10-Mar-07 16:47 
Hi,

I am having a problem decrypting a des file or well in this test case a des string. I'm not sure if my error is in the Encrypting or the Decrypting so i will post code for both. This is what i am calling.

<br />
string Key = Security.CreateKey();<br />
            Console.WriteLine(Encoding.ASCII.GetString(Security.Decrypt(Security.Encrypt(Encoding.ASCII.GetBytes("Test"), Key), Key)));<br />


But giberish is returned rather than "Test"... Obviously encoding and decoding are using the same key so i'm not exactlly sure is going on Confused | :confused: . Any help anyone could offer would be GREATLY appreciated.

Thanks in advance!

<br />
public string CreateKey()<br />
        {<br />
            DESCryptoServiceProvider desCrypto = (DESCryptoServiceProvider)DESCryptoServiceProvider.Create();<br />
            return ASCIIEncoding.ASCII.GetString(desCrypto.Key);<br />
        }<br />
<br />
public byte[] Encrypt (byte[] Data, string Key)<br />
        {<br />
            MemoryStream MemStream = new MemoryStream();<br />
            DESCryptoServiceProvider Des = new DESCryptoServiceProvider();<br />
            SetDesKey(Des, Key);<br />
<br />
            ICryptoTransform DesEncrypt = Des.CreateEncryptor();<br />
            CryptoStream CryptStream = new CryptoStream(MemStream, DesEncrypt, CryptoStreamMode.Write);<br />
            CryptStream.Write(Data, 0, Data.Length);<br />
            CryptStream.Close();<br />
<br />
            return MemStream.ToArray();<br />
        }<br />
<br />
        public byte[] Decrypt(byte[] Data, string Key)<br />
        {<br />
            byte[] returnContainer;<br />
            MemoryStream MemStream = new MemoryStream(Data);<br />
<br />
            DESCryptoServiceProvider Des = new DESCryptoServiceProvider();<br />
            SetDesKey(Des, Key);<br />
<br />
            ICryptoTransform DesEncrypt = Des.CreateEncryptor();<br />
            CryptoStream CryptStream = new CryptoStream(MemStream, DesEncrypt, CryptoStreamMode.Read);<br />
<br />
            returnContainer = new byte[MemStream.Length];<br />
            CryptStream.Read(returnContainer, 0, returnContainer.Length);<br />
            CryptStream.Close();<br />
<br />
            return returnContainer;<br />
        }<br />
<br />
private void SetDesKey(DESCryptoServiceProvider DESProvider, String password)<br />
        {<br />
            int i;<br />
            Byte[] bytePassword;<br />
            bytePassword = (new ASCIIEncoding()).GetBytes(password);<br />
            Byte[] passwordHash;<br />
            SHA1Managed SHhash = new SHA1Managed();<br />
<br />
            passwordHash = SHhash.ComputeHash(bytePassword);<br />
<br />
            Byte[] pwh = new Byte[8];<br />
            for (i = 0; i < 8; i++)<br />
                pwh[i] = passwordHash[i];<br />
<br />
            Byte[] pwiv = new Byte[8];<br />
            for (int j = 7; i < 16; i++)<br />
                pwiv[j] = passwordHash[j + 7];<br />
<br />
            DESProvider.Key = pwh;<br />
            DESProvider.IV = pwiv;<br />
        }<br />

AnswerRe: DES Encryption Pin
Dominik Reichl11-Mar-07 3:21
Dominik Reichl11-Mar-07 3:21 
GeneralRe: DES Encryption Pin
Ravun11-Mar-07 12:28
Ravun11-Mar-07 12:28 
QuestionTrail of Tears Part 2 (i.e. Control Locations)... Pin
new_phoenix10-Mar-07 12:11
new_phoenix10-Mar-07 12:11 
AnswerRe: Trail of Tears Part 2 (i.e. Control Locations)... Pin
M-Hall10-Mar-07 13:03
M-Hall10-Mar-07 13:03 
GeneralRe: Trail of Tears Part 2 (i.e. Control Locations)... Pin
Guffa10-Mar-07 13:33
Guffa10-Mar-07 13:33 
QuestionWallpaper Pin
CodeItWell10-Mar-07 11:04
CodeItWell10-Mar-07 11:04 
AnswerRe: Wallpaper Pin
Dawid Mazuruk10-Mar-07 23:36
Dawid Mazuruk10-Mar-07 23:36 
QuestionArray Pin
shamsteady10-Mar-07 9:23
shamsteady10-Mar-07 9:23 
AnswerRe: Array Pin
Travis D. Mathison10-Mar-07 9:59
Travis D. Mathison10-Mar-07 9:59 
GeneralRe: Array Pin
shamsteady10-Mar-07 10:02
shamsteady10-Mar-07 10:02 
GeneralRe: Array Pin
Christian Graus10-Mar-07 10:30
protectorChristian Graus10-Mar-07 10:30 
QuestionDifferences between strings Pin
tzuiop10-Mar-07 5:51
tzuiop10-Mar-07 5:51 
AnswerRe: Differences between strings Pin
Christian Graus10-Mar-07 5:57
protectorChristian Graus10-Mar-07 5:57 
AnswerRe: Differences between strings Pin
Phillip M. Hoff10-Mar-07 16:43
Phillip M. Hoff10-Mar-07 16:43 
Questionmove image through a path [modified] Pin
waleed9910-Mar-07 5:33
waleed9910-Mar-07 5:33 
AnswerRe: move image through a path Pin
Christian Graus10-Mar-07 5:43
protectorChristian Graus10-Mar-07 5:43 
GeneralRe: move image through a path Pin
waleed9910-Mar-07 21:13
waleed9910-Mar-07 21:13 

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.