473,569 Members | 2,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5574
string s = "<Hello>The re</Hello>";
SHA1 sha1 = SHA1.Create();
byte[] hash = sha1.ComputeHas h(Encoding.UTF8 .GetBytes(s));
Debug.WriteLine ("Hash bytes:" + hash.Length);
string base64String = Convert.ToBase6 4String(hash);
Debug.WriteLine (base64String);
Debug.WriteLine ("Len:" + base64String.Le ngth);

Output
-------------------
Hash bytes:20
kTOBvOCt/ARaUUzkd9sqwvNa cqM=
Len:28

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

"David Lownds" <da***@dlownds. f2s.com> wrote in message
news:31******** *****@individua l.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.Collecti ons
Imports System.Security
Imports System.Security .Principal
Imports System.Security .Cryptography
Imports System.Text
Dim s As String
s = "<Hello>the re</hello>"
Dim sha1 As New SHA1Managed
Dim encoding As UnicodeEncoding = New UnicodeEncoding
Dim hash As Byte() = encoding.UTF8.G etBytes(s)
Debug.WriteLine ("Hash bytes:" + hash.Length.ToS tring)
Dim base64string As String
base64String = Convert.ToBase6 4String(hash)
Debug.WriteLine (base64string)
Debug.WriteLine ("Len:" + base64string.Le ngth.ToString)

To which the result I get is

Hash bytes:20
PEhlbGxvPnRoZXJ lPC9oZWxsbz4=
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******** ******@TK2MSFTN GP10.phx.gbl...
string s = "<Hello>The re</Hello>";
SHA1 sha1 = SHA1.Create();
byte[] hash = sha1.ComputeHas h(Encoding.UTF8 .GetBytes(s));
Debug.WriteLine ("Hash bytes:" + hash.Length);
string base64String = Convert.ToBase6 4String(hash);
Debug.WriteLine (base64String);
Debug.WriteLine ("Len:" + base64String.Le ngth);

Output
-------------------
Hash bytes:20
kTOBvOCt/ARaUUzkd9sqwvNa cqM=
Len:28

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

"David Lownds" <da***@dlownds. f2s.com> wrote in message
news:31******** *****@individua l.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.Diagnost ics

Imports System.Security .Cryptography

Imports System.Text



Private Sub doTest()

Dim s As String = "<Hello>The re</Hello>"

Dim sha1 As sha1 = sha1.Create()

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



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

Dim base64String As String = Convert.ToBase6 4String(hash)

Debug.WriteLine (base64String)

Debug.WriteLine ("Len:" & base64String.Le ngth)

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******** *****@individua l.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.Collecti ons
Imports System.Security
Imports System.Security .Principal
Imports System.Security .Cryptography
Imports System.Text


Dim s As String
s = "<Hello>the re</hello>"
Dim sha1 As New SHA1Managed
Dim encoding As UnicodeEncoding = New UnicodeEncoding
Dim hash As Byte() = encoding.UTF8.G etBytes(s)
Debug.WriteLine ("Hash bytes:" + hash.Length.ToS tring)
Dim base64string As String
base64String = Convert.ToBase6 4String(hash)
Debug.WriteLine (base64string)
Debug.WriteLine ("Len:" + base64string.Le ngth.ToString)

To which the result I get is

Hash bytes:20
PEhlbGxvPnRoZXJ lPC9oZWxsbz4=
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******** ******@TK2MSFTN GP10.phx.gbl...
string s = "<Hello>The re</Hello>";
SHA1 sha1 = SHA1.Create();
byte[] hash = sha1.ComputeHas h(Encoding.UTF8 .GetBytes(s));
Debug.WriteLine ("Hash bytes:" + hash.Length);
string base64String = Convert.ToBase6 4String(hash);
Debug.WriteLine (base64String);
Debug.WriteLine ("Len:" + base64String.Le ngth);

Output
-------------------
Hash bytes:20
kTOBvOCt/ARaUUzkd9sqwvNa cqM=
Len:28

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

"David Lownds" <da***@dlownds. f2s.com> wrote in message
news:31******** *****@individua l.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******** *****@individua l.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.Collecti ons
Imports System.Security
Imports System.Security .Principal
Imports System.Security .Cryptography
Imports System.Text
Dim s As String
s = "<Hello>the re</hello>"
Dim sha1 As New SHA1Managed
Dim encoding As UnicodeEncoding = New UnicodeEncoding
Dim hash As Byte() = encoding.UTF8.G etBytes(s)
Debug.WriteLine ("Hash bytes:" + hash.Length.ToS tring)
Dim base64string As String
base64String = Convert.ToBase6 4String(hash)
Debug.WriteLine (base64string)
Debug.WriteLine ("Len:" + base64string.Le ngth.ToString)

To which the result I get is

Hash bytes:20
PEhlbGxvPnRoZXJ lPC9oZWxsbz4=
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******** ******@TK2MSFTN GP10.phx.gbl...
string s = "<Hello>The re</Hello>";
SHA1 sha1 = SHA1.Create();
byte[] hash = sha1.ComputeHas h(Encoding.UTF8 .GetBytes(s));
Debug.WriteLine ("Hash bytes:" + hash.Length);
string base64String = Convert.ToBase6 4String(hash);
Debug.WriteLine (base64String);
Debug.WriteLine ("Len:" + base64String.Le ngth);

Output
-------------------
Hash bytes:20
kTOBvOCt/ARaUUzkd9sqwvNa cqM=
Len:28

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

"David Lownds" <da***@dlownds. f2s.com> wrote in message
news:31******** *****@individua l.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******** ******@TK2MSFTN GP14.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******** *****@individua l.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.Collecti ons
Imports System.Security
Imports System.Security .Principal
Imports System.Security .Cryptography
Imports System.Text
Dim s As String
s = "<Hello>the re</hello>"
Dim sha1 As New SHA1Managed
Dim encoding As UnicodeEncoding = New UnicodeEncoding
Dim hash As Byte() = encoding.UTF8.G etBytes(s)
Debug.WriteLine ("Hash bytes:" + hash.Length.ToS tring)
Dim base64string As String
base64String = Convert.ToBase6 4String(hash)
Debug.WriteLine (base64string)
Debug.WriteLine ("Len:" + base64string.Le ngth.ToString)

To which the result I get is

Hash bytes:20
PEhlbGxvPnRoZXJ lPC9oZWxsbz4=
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******** ******@TK2MSFTN GP10.phx.gbl...
string s = "<Hello>The re</Hello>";
SHA1 sha1 = SHA1.Create();
byte[] hash = sha1.ComputeHas h(Encoding.UTF8 .GetBytes(s));
Debug.WriteLine ("Hash bytes:" + hash.Length);
string base64String = Convert.ToBase6 4String(hash);
Debug.WriteLine (base64String);
Debug.WriteLine ("Len:" + base64String.Le ngth);

Output
-------------------
Hash bytes:20
kTOBvOCt/ARaUUzkd9sqwvNa cqM=
Len:28

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

"David Lownds" <da***@dlownds. f2s.com> wrote in message
news:31******** *****@individua l.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
7133
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 CRYPTO_SEED. With the sqlnet.ora file configured for the encryption, the other 2 databases won't connect and vise versa. Is there a way to make the...
113
12236
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 algorithm work with strings that may or may not be unicode 3) Number of bytes back must either be <= number of _TCHARs in * sizeof(_TCHAR), or the...
7
2231
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 for my purposes. There seem to be quite a few different ways of doing it, and I'm not sure what's most suitable for me. Anyone any suggestions? I...
2
1527
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
5136
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 great if any sample source code provided. Thanks, Sweety
4
4132
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 same is decrypted at client side using public key and vice-versa..Now i hav confusion like i.e. * Are both the keys available to both sender and...
1
3071
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? Long version: Historically, browsers could only be exported to certain countries if they supported only 40 and 56 bit encryption; 128 bit was...
11
5024
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 debug it let me narrow the problem down to the Cipher function I think it faults at line 84 or 85. The program makes it's first read/cipher/write pass...
22
7636
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 through the code and point me in the correct direction one would be very grateful. Example Input : j1mb0jay Example Output 1 :...
19
3279
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 (md5) the password field using a random one-time salt (nonce) -- generated by php and pasted in the form -- that is then posted with the hashed...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.