Encrpytion routine - embedded nulls in BSTR

M

mtay

I’m currently working on a VC++ 2005 dll used for encrypting and decrypting
passwords to be stored in an LDAP.

This dll needs to be called by a VB6 application, so I find myself limited
(I think) to using BSTR as the return value.

The encryption routine returns a char array which frequently contains null
characters. When I convert to a BSTR I’m losing all characters after the null.

I’ve tried SysAllocStringByteLen to control the length of the BSTR
(converting the char array to LPSTR beforehand) but the BSTR bears no
resemblance to the characters I started with.

I’ve also tried SysAllocStringLen, but I’m unable to convert to the right
data type without losing the characters after the null.

Can anyone suggest a way around this? I’ve thrown everything in my limited
knowledge at it.

If I changed my end component to VB.net, would this make a difference? Can I
use data types close to the VC++ ones?
 
G

Giovanni Dicanio

mtay said:
I’m currently working on a VC++ 2005 dll used for encrypting and
decrypting
passwords to be stored in an LDAP.

This dll needs to be called by a VB6 application, so I find myself limited
(I think) to using BSTR as the return value.

The encryption routine returns a char array which frequently contains null
characters. When I convert to a BSTR I’m losing all characters after the
null.

You may want to try returning a simple array of chars, using SAFEARRAY
instead of BSTR.

HTH,
Giovanni
 
G

Giovanni Dicanio

mtay said:
I’m currently working on a VC++ 2005 dll used for encrypting and
decrypting
passwords to be stored in an LDAP.

This dll needs to be called by a VB6 application, so I find myself limited
(I think) to using BSTR as the return value.

The encryption routine returns a char array which frequently contains null
characters. When I convert to a BSTR I’m losing all characters after the
null.

You may want to try returning a simple array of chars, using SAFEARRAY
instead of BSTR.

HTH,
Giovanni
 
C

Carl Daniel [VC++ MVP]

Giovanni said:
You may want to try returning a simple array of chars, using SAFEARRAY
instead of BSTR.

Or do some post-encryption encoding, such as BASE64 so that the results are
guaranteed to be simple text.

-cd
 
C

Carl Daniel [VC++ MVP]

Giovanni said:
You may want to try returning a simple array of chars, using SAFEARRAY
instead of BSTR.

Or do some post-encryption encoding, such as BASE64 so that the results are
guaranteed to be simple text.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top