login about faq

I'm trying to understand why Encrypt stopped working. It seems it might be environmental because I know it was working, but then some time passed and when I want back to resume work on it, it no longer worked. The code hasn't changed and I don't remember any changes to the environment so I'm stumped.

The code is below It finds the cert fine, but when it calls Encrypt, it returns zero bytes when a byte array (b) is passed in. No exceptions are thrown. I'm using C#.

Cert c = store.FindCertBySubjectCN(subjectCN);  
if (c != null)  
{  
    crypt.SetEncryptCertificate(c);  
    byte[] encryptedBytes = crypt.Encrypt(b);    // returns 0 bytes  
}

asked Jun 16 at 12:41

codersteve's gravatar image

codersteve
1


Check the contents of the crypt.LastErrorText property after calling crypt.Encrypt(b);

link

answered Jun 20 at 11:11

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Thanks for the reply. Here is the value from the crypt.LastErrorText property:

logged_on_user: DOR964979$
ncsp: Microsoft Base Cryptographic Provider v1.0
alg_name: RC2
alg_bits: 40
encryptOid: 1.2.840.113549.3.2
encryptData.1: Bad Length.
Failed to encrypt data

The code hasn't changed in ages and the cert is good. Why it suddenly doesn't work is baffling to me. I see that the error says Bad Length--but why? I think it has to be the environment but can't figure it out.

link

answered Jun 22 at 10:02

codersteve's gravatar image

codersteve
1

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×64
×12

Asked: Jun 16 at 12:41

Seen: 225 times

Last updated: Jun 22 at 10:02

powered by OSQA