|
|
|
date: Tue, 6 May 2008 14:28:40 -0700 (PDT),
group: microsoft.public.dotnet.security
back
Re: RSA encrypt/decrypt of byte array
On 7 íÁÊ, 23:36, bobuva wrote:
> On May 7, 8:22 am, Arnout Grootveld <arn...@newsgroup.nospam> wrote:
>
>
>
> > bobuva wrote in news:014f714a-e412-42d2-83bf-
> > e590600aa...@24g2000hsh.googlegroups.com:
>
> > > client (encrypts):
>
> > > byte[] cipherBytes = rsa.Encrypt( bytesToEncrypt, false);
>
> > > string cipherText = Encoding.UTF8.GetString(cipherBytes);
>
> > > server (decrypts):
>
> > > byte[] encryptedBytes = Encoding.UTF8.GetBytes(cipherText);
>
> > > byte[] clearTextBytes = provider.Decrypt(encryptedBytes,
> > > false); <<--- GET EXCEPTION HERE
>
> > Bob,
>
> > The problem lies in constructing your cipherText string. Not all byte
> > sequences represent a character in UTF-8, which means that you can't just
> > feed the result of rsa.Encrypt() to Encoding.UTF8.GetString().
>
> > What you could do instead, is converting your bytes to and from Base64:
>
> > // On the client
> > string cipherText = Convert.ToBase64String(cipherBytes);
>
> > // On the server
> > byte[] encryptedBytes = Convert.FromBase64String(cipherText);
>
> > --
> > Arnout.
>
> I did try converting to/from base-64 string but got a "Bad Data" error
> from the Decrypt call. I'll look at what Joe K. recommended. Although
> it looks like I may be switching to WCF for the utility I'm working on
> instead of doing the encryption myself.
>
> Bob
Hi,
you probably using hardware CSP (smart card). RSACryptoServiceProvider
in .NET Framework 2.0 have a problem with hardware CSP. If you use for
example "Microsoft base cryptographic provider" then your code will
not generate exception. For more information see this:
http://forums.microsoft.com/msdn/ShowPost.aspx?postid=2033926&siteid=1
http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedb...
In .NET Framework 1.1 in VS2003 RSACryptoServiceProvider class work
ok.
Ivan Blagoev
date: Fri, 9 May 2008 00:17:24 -0700 (PDT)
author: unknown
|
|