Re: ??Difference Between utf8encoder.GetBytes and Encoding.ASCII.GetBytes

From: Joe Kaplan \(MVP - ADSI\) (joseph.e.kaplan_at_removethis.accenture.com)
Date: 02/24/05


Date: Thu, 24 Feb 2005 13:19:43 -0600

Generally speaking, the different encoding classes will give you an array of
bytes from a string corresponding to how that encoding actually represents a
string. Unicode (UTF16) represents each character as 2 bytes. UTF8 will
use a variable number of bytes for each character, but uses only one for
ASCII characters, so it generally uses much less space to store the same
Unicode data.

ASCII converts characters into a single byte using only 7 bits of each byte.
Since it only supports ASCII characters, it can result in data loss if the
string in question contains non-ASCII characters. It rarely has a use in
.NET crypto since strings are unicode in .NET.

If your encryption key is stored as text, it is probably stored in Base64.
In that case, you probably want to use Convert.FromBase64String to convert
the string key into a byte array.

Joe K.

"Phil C." <charlestek@rcn.com> wrote in message
news:u6LpKgpGFHA.2616@tk2msftngp13.phx.gbl...
> Hi. (Using VB.Net) I have a symmetric encryption key stored as text,
> encrytped by DPAPI in my web config that I use a handler
> class to decrypt by the DPAPI and pass to the class that does the
> encryption/decryption.
> The decrypted DPAPI key is a string and needs to be converted to a byte
> array for use by the encryption/decryption class. I'm confused as to the
> difference using utf8encoder.GetBytes() or Encoding.ASCII.GetBytes() to do
> this.
>
> Thanks,
>
> Phil
> Boston, MA
>



Relevant Pages

  • =?windows-1252?Q?Re=3A_Encrypting_Unicode_=96_Using_ASCII_as_a_Surrogat?= =?windows-1252?Q?e
    ... characters of an exotic eastern language using an ASCII keyboard. ... communicate in large volume with China or Japan using CJK from Unicode ... present the message text to Alice as a string of hexadecimal numbers ... by the computer as an external file and enciphered by a stream cipher ...
    (sci.crypt)
  • Re: Fast UTF-8 strlen function
    ... >> Is there a fast UTF-8 string length function floating around? ... Length in bytes, or length in characters? ... For UTF-8, the main basic "change" you have to make to your string routines ... then I could individually look up the characters in my UNICODE ...
    (alt.lang.asm)
  • =?windows-1252?Q?Re=3A_Encrypting_Unicode_=96_Using_ASCII_as_a_Surrogat?= =?windows-1252?Q?e
    ... characters of an exotic eastern language using an ASCII keyboard. ... communicate in large volume with China or Japan using CJK from Unicode ... present the message text to Alice as a string of hexadecimal numbers ... by the computer as an external file and enciphered by a stream cipher ...
    (sci.crypt)
  • =?windows-1252?Q?Re=3A_Encrypting_Unicode_=96_Using_ASCII_as_a_Surrogat?= =?windows-1252?Q?e
    ... characters of an exotic eastern language using an ASCII keyboard. ... communicate in large volume with China or Japan using CJK from Unicode ... present the message text to Alice as a string of hexadecimal numbers ... by the computer as an external file and enciphered by a stream cipher ...
    (sci.crypt)
  • Re: Prothon should not borrow Python strings!
    ... """It does not make sense to have a string without knowing what encoding ... same cul de sac as Python. ... Prothon_String_As_ASCII // raises error if there are high characters ... Python's split between byte strings and Unicode strings is ...
    (comp.lang.python)