Leif,
    This is the .Net code fragment I am trying to match on the AS/400.  I'm
now think to ask my counterpart to use UTF8:

// create the plain text by adding string1 and string2
string plainText = string1 + string2;

// turn the plain text into an array of bytes, using Unicode (ASCII won't
match!)
byte[] buffer = Encoding.Unicode.GetBytes(plainText);

// initialize the SHA1 cryptography routine
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();

// compute the hash of the buffer
byte[] hash = sha1.ComputeHash(buffer);

// intiate a quick way to build a string
StringBuilder b = new StringBuilder();

// convert the hashed byte array to a hexadecimal string
for (int i = 0; i < hash.Length; i++)
 b.Append(hash[i].ToString("x02", NumberFormatInfo.InvariantInfo));

// return the hexadecimal string
return b.ToString();

I think an article at http://www.eggheadcafe.com/articles/20020630.asp
explains my Unicode issue:
Also, I'd lke to thank Shawn Steele of Microsoft who suggested changing my
original choice of Encoding.Default.GetBytes/String to
Encoding.UTF8.GetBytes/String (or Unicode, which is my choice here). The
reason is that Encoding.Default provides the windows default code page
behavior for your machine (so it can be different if you run it on different
machines), and also it maps some characters to their "best-fit" counterparts
if they don't exist in that code page. For example, É and È could both be
best fit to E in some code pages. That probably isn't good behavior for
encryption. UTF8 (or Unicode) provides mappings for all characters, so the
best fit issue isn't a problem. Explicitly stating the code page prevents
non-ASCII character gibberish if its decoded on another machine with a
different system locale.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.