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)  
    byte[] encryptedBytes = crypt.Encrypt(b);    // returns 0 bytes  

asked Jun 16 '16 at 12:41

codersteve's gravatar image


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


answered Jun 20 '16 at 11:11

chilkat's gravatar image

chilkat ♦♦

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.


answered Jun 22 '16 at 10:02

codersteve's gravatar image


Your answer
toggle preview

Follow this question

By Email:

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



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



Asked: Jun 16 '16 at 12:41

Seen: 1,070 times

Last updated: Jun 22 '16 at 10:02

powered by OSQA