Click here to Skip to main content
15,892,480 members
Home / Discussions / C#
   

C#

 
QuestionHow to read the words from a pdf? Pin
Tomerland2-Jul-07 2:19
Tomerland2-Jul-07 2:19 
AnswerRe: How to read the words from a pdf? Pin
CPallini2-Jul-07 3:43
mveCPallini2-Jul-07 3:43 
QuestionDataGrid paging not working Pin
Jax_qqq2-Jul-07 1:26
Jax_qqq2-Jul-07 1:26 
QuestionLine code Pin
merwa2-Jul-07 1:16
merwa2-Jul-07 1:16 
AnswerRe: Line code Pin
Jimmanuel2-Jul-07 2:36
Jimmanuel2-Jul-07 2:36 
QuestionTCP channel v/s HTTP channel Pin
amitcoder832-Jul-07 0:35
amitcoder832-Jul-07 0:35 
AnswerRe: TCP channel v/s HTTP channel Pin
originSH2-Jul-07 2:40
originSH2-Jul-07 2:40 
QuestionProblem with symetric algorithm (Rihndael) Pin
FernandoCR2-Jul-07 0:20
FernandoCR2-Jul-07 0:20 
I am try crypt and decrypt the same text. I am use a symetric algorithm (Rijndael), but I don´t understand what happend whit my code. This is the test.
1. I write a text in a textbox (txtSrc).
2. I read the text, crypt it and write it in a label (lblCph1).
3. I read the text in the label and again crypt it y write the result in other label (lblCph2).
In the point 2, I expect the text of the label with strange simbols (cipher it), and in the pint 3 I expect the text of the label in plain text, but it is in strange simbols too. I don´t undertand, I think what if I crypt a text with the same key a pair of time, it will be decrypted. ¿Someone can explain to me?

I have write a example code.


<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Security.Cryptography;<br />
using System.IO;<br />
<br />
namespace PruebaSimetrica<br />
{<br />
    public partial class Form1 : Form<br />
    {<br />
        public Form1()<br />
        {<br />
            InitializeComponent();<br />
        }<br />
<br />
        private void Form1_Load(object sender, EventArgs e)<br />
        {<br />
<br />
        }<br />
<br />
        private void btnCph1_Click(object sender, EventArgs e)<br />
        {<br />
            //Gererate a Key and IV<br />
            byte[] RellenoKey = new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };<br />
            byte[] RellenoIV = new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };<br />
            // Create a new Rijndael object.<br />
            Rijndael RijndaelAlg = Rijndael.Create();<br />
            RijndaelAlg.Key = RellenoKey;<br />
            RijndaelAlg.IV = RellenoIV;<br />
            //Get the plain text<br />
            byte[] bytePlainText = Encoding.Default.GetBytes(txtSrc.Text);<br />
            byte[] byteCryptText;<br />
            <br />
            bytePlainText = Encoding.Default.GetBytes(txtSrc.Text);<br />
<br />
            MemoryStream mStream = new MemoryStream();<br />
            // Create a CryptoStream using the MemoryStream <br />
            // and the passed key and initialization vector (IV).<br />
            CryptoStream cStream = new CryptoStream(mStream, RijndaelAlg.CreateEncryptor(RijndaelAlg.Key, RijndaelAlg.IV), CryptoStreamMode.Write);<br />
<br />
            cStream.Write(bytePlainText, 0, bytePlainText.Length);<br />
            cStream.FlushFinalBlock();<br />
                        <br />
            byteCryptText = mStream.ToArray();<br />
<br />
            lblcph1.Text = System.Text.Encoding.Default.GetString(byteCryptText);<br />
            <br />
            cStream.Close();<br />
            mStream.Close();<br />
        }<br />
<br />
        private void btnCph2_Click(object sender, EventArgs e)<br />
        {<br />
            //Gererate the same Key and IV<br />
            byte[] RellenoKey = new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };<br />
            byte[] RellenoIV = new byte[] { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };<br />
            Rijndael RijndaelAlg = Rijndael.Create();<br />
            RijndaelAlg.Key = RellenoKey;<br />
            RijndaelAlg.IV = RellenoIV;<br />
            byte[] bytePlainText  ;<br />
            byte[] byteCryptText=Encoding.Default.GetBytes(lblcph1.Text);<br />
<br />
            byteCryptText = Encoding.Default.GetBytes(lblcph1.Text);<br />
<br />
            MemoryStream mStream = new MemoryStream();<br />
<br />
            CryptoStream cStream = new CryptoStream(mStream, RijndaelAlg.CreateEncryptor(RijndaelAlg.Key, RijndaelAlg.IV), CryptoStreamMode.Write);<br />
<br />
            cStream.Write(byteCryptText, 0, byteCryptText.Length);<br />
            cStream.FlushFinalBlock();<br />
<br />
            bytePlainText = mStream.ToArray();<br />
<br />
            lblCph2.Text = System.Text.Encoding.Default.GetString(bytePlainText);<br />
<br />
            cStream.Close();<br />
            mStream.Close();<br />
        }<br />
 <br />
    }<br />
}


Thanks,
Fernando
AnswerRe: Problem with symetric algorithm (Rihndael) Pin
Abisodun2-Jul-07 2:41
Abisodun2-Jul-07 2:41 
GeneralRe: Problem with symetric algorithm (Rihndael) Pin
FernandoCR3-Jul-07 1:13
FernandoCR3-Jul-07 1:13 
QuestionReading color of each entity in DXF file Pin
a_david1232-Jul-07 0:16
a_david1232-Jul-07 0:16 
Questionwriting a hardware lock Pin
logicaldna1-Jul-07 23:36
logicaldna1-Jul-07 23:36 
AnswerRe: writing a hardware lock Pin
Luc Pattyn1-Jul-07 23:50
sitebuilderLuc Pattyn1-Jul-07 23:50 
GeneralRe: writing a hardware lock Pin
logicaldna2-Jul-07 0:19
logicaldna2-Jul-07 0:19 
QuestionExporting data from database to a file, zipping it and mailing Pin
I.explore.code1-Jul-07 23:22
I.explore.code1-Jul-07 23:22 
AnswerRe: Exporting data from database to a file, zipping it and mailing Pin
nitikin2-Jul-07 0:16
nitikin2-Jul-07 0:16 
QuestionProblem in closing the login window Pin
I.explore.code1-Jul-07 23:15
I.explore.code1-Jul-07 23:15 
AnswerRe: Problem in closing the login window Pin
logicaldna1-Jul-07 23:41
logicaldna1-Jul-07 23:41 
AnswerRe: Problem in closing the login window Pin
Martin#1-Jul-07 23:44
Martin#1-Jul-07 23:44 
AnswerRe: Problem in closing the login window Pin
Navneet Hegde2-Jul-07 1:56
Navneet Hegde2-Jul-07 1:56 
QuestionHow to augment space between the TreeNodes? Pin
jason_mf1-Jul-07 23:14
jason_mf1-Jul-07 23:14 
QuestionMembership API Pin
sangramkp1-Jul-07 22:32
sangramkp1-Jul-07 22:32 
AnswerRe: Membership API Pin
Luc Pattyn1-Jul-07 23:39
sitebuilderLuc Pattyn1-Jul-07 23:39 
AnswerRe: Membership API Pin
Pete O'Hanlon2-Jul-07 4:10
mvePete O'Hanlon2-Jul-07 4:10 
QuestionDock bounds Pin
Stevo Z1-Jul-07 22:09
Stevo Z1-Jul-07 22:09 

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.