Click here to Skip to main content
15,921,716 members
Home / Discussions / C#
   

C#

 
AnswerRe: mouse position in array Pin
Dawid Mazuruk18-Mar-07 11:17
Dawid Mazuruk18-Mar-07 11:17 
QuestionHow to use Triggers in Sql Server 2005 ? Pin
hdv21218-Mar-07 8:44
hdv21218-Mar-07 8:44 
AnswerRe: How to use Triggers in Sql Server 2005 ? Pin
Christian Graus18-Mar-07 10:26
protectorChristian Graus18-Mar-07 10:26 
GeneralRe: How to use Triggers in Sql Server 2005 ? Pin
hdv21218-Mar-07 12:22
hdv21218-Mar-07 12:22 
GeneralRe: How to use Triggers in Sql Server 2005 ? Pin
Christian Graus18-Mar-07 12:30
protectorChristian Graus18-Mar-07 12:30 
QuestionButtons with run-time adjustable images Pin
lupus8118-Mar-07 8:15
lupus8118-Mar-07 8:15 
AnswerRe: Buttons with run-time adjustable images Pin
Christian Graus18-Mar-07 8:32
protectorChristian Graus18-Mar-07 8:32 
Questionbyte array to string and back encoding problem Pin
zuidgeest18-Mar-07 8:03
zuidgeest18-Mar-07 8:03 
I'm building an application that needs to sign some text. and than save the text and the signature in a file. Another application than reads this file and verifies it's contents using this hash. For this to work as I want, I need to convert the byte array containing the signature to a string to put at the end of the file. Next the recipient reads the string and converts it back to an byte array so the text can be verified.

I us the next code example to test. there are two blocks of code one using Encoding.Default and one using Encoding.Unicode. Using encoding.default works and give the correct answer true, the other does not.

Can anyone explain why using encoding.unicode doesn't work, or at least how to do the string <-> byte array conversions codepage independent?


<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 />
<br />
namespace WindowsApplication1<br />
{<br />
    public partial class Form1 : Form<br />
    {<br />
        public Form1()<br />
        {<br />
            InitializeComponent();<br />
<br />
<br />
            RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();<br />
<br />
            byte [] signature = RSA.SignData(Encoding.Unicode.GetBytes("test"), "SHA1");<br />
<br />
            // this should be system codepage independent but doesn't work            <br />
            //string temp = System.Text.Encoding.Unicode.GetString(signature);<br />
            //signature = System.Text.Encoding.Unicode.GetBytes(temp);<br />
<br />
            // this works but is system codepage dependent            <br />
            string temp = Encoding.Default.GetString(signature);<br />
            signature = Encoding.Default.GetBytes(temp);<br />
<br />
            bool verified = RSA.VerifyData(Encoding.Unicode.GetBytes("test"), "SHA1", signature);<br />
                        <br />
            MessageBox.Show(verified.ToString());<br />
<br />
        }<br />
    }<br />
}<br />

AnswerRe: byte array to string and back encoding problem Pin
Guffa18-Mar-07 8:18
Guffa18-Mar-07 8:18 
GeneralRe: byte array to string and back encoding problem Pin
zuidgeest18-Mar-07 10:26
zuidgeest18-Mar-07 10:26 
Questionrandom sql Pin
ujupanmester18-Mar-07 6:10
ujupanmester18-Mar-07 6:10 
AnswerRe: random sql Pin
Mudsoad18-Mar-07 7:07
Mudsoad18-Mar-07 7:07 
GeneralRe: random sql Pin
ujupanmester18-Mar-07 15:02
ujupanmester18-Mar-07 15:02 
Questionopening file with my program Pin
dsl/fahk18-Mar-07 3:59
dsl/fahk18-Mar-07 3:59 
AnswerRe: opening file with my program Pin
Stefan Troschuetz18-Mar-07 4:36
Stefan Troschuetz18-Mar-07 4:36 
AnswerRe: opening file with my program Pin
Wayne Phipps18-Mar-07 5:01
Wayne Phipps18-Mar-07 5:01 
QuestionRe: opening file with my program Pin
dsl/fahk19-Mar-07 15:04
dsl/fahk19-Mar-07 15:04 
AnswerRe: opening file with my program Pin
Wayne Phipps20-Mar-07 10:27
Wayne Phipps20-Mar-07 10:27 
QuestionMicrosoft Office Translations Pin
mm31018-Mar-07 3:55
mm31018-Mar-07 3:55 
AnswerRe: Microsoft Office Translations Pin
Ed.Poore19-Mar-07 13:03
Ed.Poore19-Mar-07 13:03 
QuestionProblem receiving data through serial port Pin
naffilk18-Mar-07 2:46
naffilk18-Mar-07 2:46 
AnswerRe: Problem receiving data through serial port Pin
rbirkelbach19-Mar-07 5:03
rbirkelbach19-Mar-07 5:03 
Questionc# word xp textbox Pin
spinis18-Mar-07 0:00
spinis18-Mar-07 0:00 
AnswerRe: c# word xp textbox Pin
Thomas Stockwell19-Mar-07 8:26
professionalThomas Stockwell19-Mar-07 8:26 
QuestionBioinformatic algorithms in C# Pin
bufugus17-Mar-07 23:50
bufugus17-Mar-07 23:50 

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.