RSADecrypt has internal Nil Obj Exception

RSAEncrypting an empty string and then RSADecrypting it results in an NOE instead of returning an empty string as expected.

The first two examples below work fine, but the decrypt line of the third example raises an NOE. It appears the exception occurs within the RSADecrypt method.

[code] dim encrypted, decrypted as string

	encrypted = Crypto.RSAEncrypt ("Test string junk", PublicEncryptKey)
	decrypted = Crypto.RSADecrypt (encrypted, PrivateDecryptKey)
	
	encrypted = Crypto.RSAEncrypt ("J", PublicEncryptKey)
	decrypted = Crypto.RSADecrypt (encrypted, PrivateDecryptKey)
	
	encrypted = Crypto.RSAEncrypt ("", PublicEncryptKey)
	decrypted = Crypto.RSADecrypt (encrypted, PrivateDecryptKey) // <---NOE here
	[/code]

converting a nil memoryblock to string causes exception.

Maybe you use memory blocks here?

Hi Christian

Yes that’s a very good point, it’s probably related to something like that… IMHO an empty string/memoryblock should exist but be empty, so I’d consider that a bug in RSAdecrypt…

FWIW RSAEncrypt does create a full length encrypted data block from an empty string “”, but trying to decrypt it fails with an NOE

Since I control the encrypting side too, I’ve worked around this by storing an empty string as the encrypted value for empty strings and then testing for that case before attempting to decrypt it on the other end.

You don’t need that.

decrypted should be a memoryblock.
By having it a string you require an extra copy to be created which raises the exception.