473,385 Members | 1,553 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

XML Encryption

Dear All,

I need to do the following to an xml file in vb.net.

- Read in the file

- canonicalise (c14n) the XML document
- generate a 160-bit binary secure hash from the canonicalise XML

using the SHA-1 algorithm

- encode the binary data using base-64 to produce a 28 character string

Can anyone provide me with some help ? I'm very stuck on this.
--
Cheers

Dave
Nov 12 '05 #1
5 5567
string s = "<Hello>There</Hello>";
SHA1 sha1 = SHA1.Create();
byte[] hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(s));
Debug.WriteLine("Hash bytes:" + hash.Length);
string base64String = Convert.ToBase64String(hash);
Debug.WriteLine(base64String);
Debug.WriteLine("Len:" + base64String.Length);

Output
-------------------
Hash bytes:20
kTOBvOCt/ARaUUzkd9sqwvNacqM=
Len:28

--
William Stacey, MVP
http://mvp.support.microsoft.com

"David Lownds" <da***@dlownds.f2s.com> wrote in message
news:31*************@individual.net...
Dear All,

I need to do the following to an xml file in vb.net.

- Read in the file

- canonicalise (c14n) the XML document
- generate a 160-bit binary secure hash from the canonicalise XML

using the SHA-1 algorithm

- encode the binary data using base-64 to produce a 28 character string

Can anyone provide me with some help ? I'm very stuck on this.
--
Cheers

Dave


Nov 12 '05 #2
Hi William,

Thank you very much for your quick response.

I'm not very familiar with c# so I've tried to convert your code to vb.net .

My interpretation is

Imports System
Imports System.Collections
Imports System.Security
Imports System.Security.Principal
Imports System.Security.Cryptography
Imports System.Text
Dim s As String
s = "<Hello>there</hello>"
Dim sha1 As New SHA1Managed
Dim encoding As UnicodeEncoding = New UnicodeEncoding
Dim hash As Byte() = encoding.UTF8.GetBytes(s)
Debug.WriteLine("Hash bytes:" + hash.Length.ToString)
Dim base64string As String
base64String = Convert.ToBase64String(hash)
Debug.WriteLine(base64string)
Debug.WriteLine("Len:" + base64string.Length.ToString)

To which the result I get is

Hash bytes:20
PEhlbGxvPnRoZXJlPC9oZWxsbz4=
Len:28

This is different to your result. Not being an expert at this can you
confirm that what I've done is correct ?

Many many thanks for your help on this.

Dave
"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:e8**************@TK2MSFTNGP10.phx.gbl...
string s = "<Hello>There</Hello>";
SHA1 sha1 = SHA1.Create();
byte[] hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(s));
Debug.WriteLine("Hash bytes:" + hash.Length);
string base64String = Convert.ToBase64String(hash);
Debug.WriteLine(base64String);
Debug.WriteLine("Len:" + base64String.Length);

Output
-------------------
Hash bytes:20
kTOBvOCt/ARaUUzkd9sqwvNacqM=
Len:28

--
William Stacey, MVP
http://mvp.support.microsoft.com

"David Lownds" <da***@dlownds.f2s.com> wrote in message
news:31*************@individual.net...
Dear All,

I need to do the following to an xml file in vb.net.

- Read in the file

- canonicalise (c14n) the XML document
- generate a 160-bit binary secure hash from the canonicalise XML

using the SHA-1 algorithm

- encode the binary data using base-64 to produce a 28 character string

Can anyone provide me with some help ? I'm very stuck on this.
--
Cheers

Dave

Nov 12 '05 #3
In VB you would have...

Imports System

Imports System.Diagnostics

Imports System.Security.Cryptography

Imports System.Text



Private Sub doTest()

Dim s As String = "<Hello>There</Hello>"

Dim sha1 As sha1 = sha1.Create()

Dim hash() As Byte = sha1.ComputeHash(Encoding.UTF8.GetBytes(s))



Debug.WriteLine("Hash bytes:" & hash.Length)

Dim base64String As String = Convert.ToBase64String(hash)

Debug.WriteLine(base64String)

Debug.WriteLine("Len:" & base64String.Length)

End Sub

ps: I have not tested it.. just converted C# to VB.

Wole

"David Lownds" <da***@dlownds.f2s.com> wrote in message news:31*************@individual.net...
Hi William,

Thank you very much for your quick response.

I'm not very familiar with c# so I've tried to convert your code to vb.net .

My interpretation is

Imports System
Imports System.Collections
Imports System.Security
Imports System.Security.Principal
Imports System.Security.Cryptography
Imports System.Text


Dim s As String
s = "<Hello>there</hello>"
Dim sha1 As New SHA1Managed
Dim encoding As UnicodeEncoding = New UnicodeEncoding
Dim hash As Byte() = encoding.UTF8.GetBytes(s)
Debug.WriteLine("Hash bytes:" + hash.Length.ToString)
Dim base64string As String
base64String = Convert.ToBase64String(hash)
Debug.WriteLine(base64string)
Debug.WriteLine("Len:" + base64string.Length.ToString)

To which the result I get is

Hash bytes:20
PEhlbGxvPnRoZXJlPC9oZWxsbz4=
Len:28

This is different to your result. Not being an expert at this can you
confirm that what I've done is correct ?

Many many thanks for your help on this.

Dave


"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:e8**************@TK2MSFTNGP10.phx.gbl...
string s = "<Hello>There</Hello>";
SHA1 sha1 = SHA1.Create();
byte[] hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(s));
Debug.WriteLine("Hash bytes:" + hash.Length);
string base64String = Convert.ToBase64String(hash);
Debug.WriteLine(base64String);
Debug.WriteLine("Len:" + base64String.Length);

Output
-------------------
Hash bytes:20
kTOBvOCt/ARaUUzkd9sqwvNacqM=
Len:28

--
William Stacey, MVP
http://mvp.support.microsoft.com

"David Lownds" <da***@dlownds.f2s.com> wrote in message
news:31*************@individual.net...
> Dear All,
>
> I need to do the following to an xml file in vb.net.
>
> - Read in the file
>
> - canonicalise (c14n) the XML document
> - generate a 160-bit binary secure hash from the canonicalise XML
>
> using the SHA-1 algorithm
>
> - encode the binary data using base-64 to produce a 28 character string
>
> Can anyone provide me with some help ? I'm very stuck on this.
> --
> Cheers
>
> Dave
>
>


Nov 12 '05 #4
I think the diff is an "h" instead of "H" in your "s" var is different.
Only one bit can change the SHA hash result a lot.

--
William Stacey, MVP
http://mvp.support.microsoft.com

"David Lownds" <da***@dlownds.f2s.com> wrote in message
news:31*************@individual.net...
Hi William,

Thank you very much for your quick response.

I'm not very familiar with c# so I've tried to convert your code to vb.net ..
My interpretation is

Imports System
Imports System.Collections
Imports System.Security
Imports System.Security.Principal
Imports System.Security.Cryptography
Imports System.Text
Dim s As String
s = "<Hello>there</hello>"
Dim sha1 As New SHA1Managed
Dim encoding As UnicodeEncoding = New UnicodeEncoding
Dim hash As Byte() = encoding.UTF8.GetBytes(s)
Debug.WriteLine("Hash bytes:" + hash.Length.ToString)
Dim base64string As String
base64String = Convert.ToBase64String(hash)
Debug.WriteLine(base64string)
Debug.WriteLine("Len:" + base64string.Length.ToString)

To which the result I get is

Hash bytes:20
PEhlbGxvPnRoZXJlPC9oZWxsbz4=
Len:28

This is different to your result. Not being an expert at this can you
confirm that what I've done is correct ?

Many many thanks for your help on this.

Dave
"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:e8**************@TK2MSFTNGP10.phx.gbl...
string s = "<Hello>There</Hello>";
SHA1 sha1 = SHA1.Create();
byte[] hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(s));
Debug.WriteLine("Hash bytes:" + hash.Length);
string base64String = Convert.ToBase64String(hash);
Debug.WriteLine(base64String);
Debug.WriteLine("Len:" + base64String.Length);

Output
-------------------
Hash bytes:20
kTOBvOCt/ARaUUzkd9sqwvNacqM=
Len:28

--
William Stacey, MVP
http://mvp.support.microsoft.com

"David Lownds" <da***@dlownds.f2s.com> wrote in message
news:31*************@individual.net...
Dear All,

I need to do the following to an xml file in vb.net.

- Read in the file

- canonicalise (c14n) the XML document
- generate a 160-bit binary secure hash from the canonicalise XML

using the SHA-1 algorithm

- encode the binary data using base-64 to produce a 28 character string
Can anyone provide me with some help ? I'm very stuck on this.
--
Cheers

Dave



Nov 12 '05 #5
Thanks William & Wole for your help.

Very much appreciated.

Dave
"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:#1**************@TK2MSFTNGP14.phx.gbl...
I think the diff is an "h" instead of "H" in your "s" var is different.
Only one bit can change the SHA hash result a lot.

--
William Stacey, MVP
http://mvp.support.microsoft.com

"David Lownds" <da***@dlownds.f2s.com> wrote in message
news:31*************@individual.net...
Hi William,

Thank you very much for your quick response.

I'm not very familiar with c# so I've tried to convert your code to vb.net
.

My interpretation is

Imports System
Imports System.Collections
Imports System.Security
Imports System.Security.Principal
Imports System.Security.Cryptography
Imports System.Text
Dim s As String
s = "<Hello>there</hello>"
Dim sha1 As New SHA1Managed
Dim encoding As UnicodeEncoding = New UnicodeEncoding
Dim hash As Byte() = encoding.UTF8.GetBytes(s)
Debug.WriteLine("Hash bytes:" + hash.Length.ToString)
Dim base64string As String
base64String = Convert.ToBase64String(hash)
Debug.WriteLine(base64string)
Debug.WriteLine("Len:" + base64string.Length.ToString)

To which the result I get is

Hash bytes:20
PEhlbGxvPnRoZXJlPC9oZWxsbz4=
Len:28

This is different to your result. Not being an expert at this can you
confirm that what I've done is correct ?

Many many thanks for your help on this.

Dave
"William Stacey [MVP]" <st***********@mvps.org> wrote in message
news:e8**************@TK2MSFTNGP10.phx.gbl...
string s = "<Hello>There</Hello>";
SHA1 sha1 = SHA1.Create();
byte[] hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(s));
Debug.WriteLine("Hash bytes:" + hash.Length);
string base64String = Convert.ToBase64String(hash);
Debug.WriteLine(base64String);
Debug.WriteLine("Len:" + base64String.Length);

Output
-------------------
Hash bytes:20
kTOBvOCt/ARaUUzkd9sqwvNacqM=
Len:28

--
William Stacey, MVP
http://mvp.support.microsoft.com

"David Lownds" <da***@dlownds.f2s.com> wrote in message
news:31*************@individual.net...
> Dear All,
>
> I need to do the following to an xml file in vb.net.
>
> - Read in the file
>
> - canonicalise (c14n) the XML document
> - generate a 160-bit binary secure hash from the canonicalise XML
>
> using the SHA-1 algorithm
>
> - encode the binary data using base-64 to produce a 28 character

string >
> Can anyone provide me with some help ? I'm very stuck on this.
> --
> Cheers
>
> Dave
>
>


Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Cliff | last post by:
We are trying to connect to 3 different Oracle databases using MS Access as the front-end and ODBC as the connection. The problem that we are having is that 1 of the databases requires a...
113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
7
by: Alan Silver | last post by:
Hello, I am writing a page where sensitive data is collected (over SSL) and stored in a database. I have been looking at the .NET encryption classes, but am a bit confused as to which is best...
2
by: Sumit Gupta | last post by:
Can anyone please tell me how to encrpt string or any kind of Data. Also the Algorithm of Compression. Any Link tutorial etc. Like : Zip or RAR Formats etc.
9
by: sweety | last post by:
Dear All, How to encrypt a C data file and make binary file and then have to read a bin file at run time and decrypt the file and have to read the data. Any help to achive this pls. Would be...
4
by: pintu | last post by:
Hello everybody.. I hav some confusion regarding asymmetric encryption.As asymmetric encryption it there is one private key and one public key.So any data is encrypted using private key and the...
1
by: =?Utf-8?B?bWljcm9ob2Y=?= | last post by:
Short version: Is there a way to configure (preferably programmatically) the max encryption strength that will be used by the framework when connecting to a particular SSL-protected web service? ...
11
by: John Williams | last post by:
I've written a simple program to do XOR encryption as my first foray into understanding how encryption works. The code compiles fine, however it segmentation faults on every run. using gdb to...
22
by: j1mb0jay | last post by:
I have had to create a simple string encryption program for coursework, I have completed the task and now have to do a write up on how it could be improved at a later date. If you could look...
19
by: klenwell | last post by:
Another request for comments here. I'd like to accomplish something like the scheme outlined at this page here: http://tinyurl.com/3dtcdr In a nutshell, the form uses javascript to hash...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.