Re: RSA Decryption Error- HELP!
From: Ivan Medvedev [MS] (ivanmed@online.microsoft.com)
Date: 01/04/03
- Next message: Ivan Medvedev [MS]: "Re: Simple Encryption/Decryption"
- Previous message: Ivan Medvedev [MS]: "Encrypt/decrypt sample for yall (code inside)"
- In reply to: PJ Acayan: "RSA Decryption Error- HELP!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
From: "Ivan Medvedev [MS]" <ivanmed@online.microsoft.com> Date: Fri, 3 Jan 2003 15:46:55 -0800
PJ,
how do you assign this.StringValue? Perhaps you are not using base64
encoding and just trying to convert bytes into a string directly. This will
not work correctly because not all bytes can be converted to a character and
back (for example, 0 does not have a character corresponding to it). If you
must store encrypted data in textual form you should use something like
base64 encoding.
Hope this helps.
Thanks,
--Ivan
"PJ Acayan" <pklefty@earthlink.net> wrote in message
news:eNAFEb2sCHA.2484@TK2MSFTNGP10...
> ok...I was able to get the private key by getting the certificate from the
> localmachine store.
>
>
> using System;
> using SystemCrypto = System.Security.Cryptography;
> using SystemX509 = System.Security.Cryptography.X509Certificates;
> using CryptoXML = System.Security.Cryptography.Xml;
> using WebServiceX509 = Microsoft.Web.Services.Security.X509;
> using WebServiceSecurity = Microsoft.Web.Services.Security;
> ...
>
> public byte[] Decrypt()
> {
> //load the certificate
> WebServiceX509.X509CertificateStore wstore =
> WebServiceX509.X509CertificateStore.LocalMachineStore("Personal");
> wstore.Open();
> foreach(WebServiceX509.X509Certificate cert in
> wstore.Certificates)
> {
> if(cert.GetName()=="CN=ACME Company")
> {
> //box the certificate publickey into an rsa object
>
> WebServiceSecurity.AsymmetricDecryptionKey asd = new
>
WebServiceSecurity.AsymmetricDecryptionKey((SystemCrypto.AsymmetricAlgorithm
> )cert.Key);
>
> SystemCrypto.RSA scr = cert.Key;
> //unbox into an RSA Provider
> SystemCrypto.RSACryptoServiceProvider rsasp =
> (SystemCrypto.RSACryptoServiceProvider)scr;
> //decrypt the string using the private key
> this.ByteArrayResult =
>
rsasp.Decrypt(System.Text.Encoding.Default.GetBytes(this.StringValue),true);
> //convert the byte array into a string for viewing
> this.StringResult =
> System.Text.Encoding.Default.GetString(this.ByteArrayResult);
> break;
> }
> }
>
> return this.ByteArrayResult;
> };
>
>
> now...when I try to decrypt I get the following error:
>
> Error occurred while decoding OAEP padding
>
> when I change the parameter for the decrypt to false I get:
>
> Bad Key
>
> Any thoughts? I'm getting my *** kicked with this one.
>
>
- Next message: Ivan Medvedev [MS]: "Re: Simple Encryption/Decryption"
- Previous message: Ivan Medvedev [MS]: "Encrypt/decrypt sample for yall (code inside)"
- In reply to: PJ Acayan: "RSA Decryption Error- HELP!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]