[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ms-cryptoapi
Subject:    Re: Need help with CryptExportKey
From:       Harry Whitehouse <harry () ENVMGR ! COM>
Date:       1998-03-24 19:37:18
[Download RAW message or body]


Andre -- Glad this worked!

In C, you would call the API first with a NULL instead of sKeyBlob.  That
would get the required size for the blob ( in your case 84).  Then you
would _dynamically_ allocate the string (I'm not sure how one goes about
this in VB, but in C you would malloc or new).  Then you call the API again
with the pointer to the newly allocated string.

Regards,

Harry


-----Original Message-----
From:   Andre Lomoy [SMTP:AndreL@SYSDATA.NO]
Sent:   Tuesday, March 24, 1998 1:28 AM
To:     CryptoAPI@DISCUSS.MICROSOFT.COM
Subject:        Re: Need help with CryptExportKey

Your third pop quiz somehow got me going...

When using a fixed-length string        (Dim sKeyBlob as String * 1000)
and setting lBlobLen equal to the length of sKeyBlob prior to
calling CryptExportKey -- it works!

lBlobLen returns 84, and the 84 first characters in sKeyBlob look
something like this:

     $  RSA1        -Ye'a*UCaoe??Y' y? Qk?D xa ??pWyoP? zloeo
EyoeA)? a"??O?$E[Boi?

(Funny how such a scrambled looking punch line could make such an happy
end :)

I'm wasting some memory having to over-size the string variable,
but until someone posts a more ideal VB solution, I'll stick to what
works.


Thanks, again!

Andre

> -----Opprinnelig melding-----
> Fra:  Harry Whitehouse [SMTP:harry@ENVMGR.COM]
> Sendt:        23. mars 1998 21:01
> Til:  CryptoAPI@DISCUSS.MICROSOFT.COM
> Emne: Re: Need help with CryptExportKey
>
> Andre --
>
> What kind of key pair did you create?  RSA/DSS?
>
> When CryptExportKey returned true, what was the value of IBlobLen
> returned?
> What did you set the value prior to calling CryptExportKey?
>
> I don't do VB coding, so I don't know the data types.  In C, I used a
> BYTE or unsigned char array for
> byteKeyBlob and the export works fine.
>
> Regards,
>
> Harry
>
> -----Original Message-----
> From:   Andre Lomoy ESMTP:AndreL@SYSDATA.NOA
> Sent:   Monday, March 23, 1998 3:56 AM
> To:     CryptoAPI@DISCUSS.MICROSOFT.COM
> Subject:        Re: Need help with CryptExportKey
>
> Thank you for your answer and the WinErr.h file.
>
> Seems like  vbNullChar  is not recognized as Null. After replacing
> vbNullChar  with  vbNullString  I no longer get Error_More_Data.
>
>
> When calling CryptExportKey the second time with pbData <> Null
> the function returns True (no error), but pbData contains no data...
> Using an array of bytes, I get nothing but zeros. I've tried other
> data types as well, but the variable always comes out unchanged.
>
>     'Attempt to export public key blob
>     If Not CBool(CryptExportKey(lHSignKey, 0, 6, 0, byteKeyBlob,
> lBlobLen)) Then
>         MsgBox "Failed to export public key (" & Err.LastDllError &
> ")",
> vbCritical, "CryptExportKey"
>         GoTo ExitFunction
>     End If
>
> I've even tried to use the Crypt_Exportable flag when creating the key
> pair, even though the documentation says this flag does not apply to
> public/private key pairs.
>
>
> How can I get CryptExportKey to give me the blob data, using Visual
> Basic?
>
>
> Thank you for any help
> Andre
>
>
> > -----Opprinnelig melding-----
> > Fra:  Harry Whitehouse ESMTP:harry@ENVMGR.COMA
> > Sendt:        22. mars 1998 20:22
> > Til:  CryptoAPI@DISCUSS.MICROSOFT.COM
> > Emne: Re: Need help with CryptExportKey
> >
> > Andre --- ?define ERROR_MORE_DATA                  234L
> >
> > This can occurr if you have failed to set IBlobLen to a large
> enought
> > value
> > _prior_ to the API call, but I was under the impression that this
> > error
> > occurred only when the second from the last parameter was non-null.
> >  Evidently, you have NULL in that parameter, so it should return the
> > blob
> > size with no error.
> >
> > I'll mail you a copy of my winerr.h directly.
> >
> > HTH
> >
> > Harry
> >
> >
> >
> > -----Original Message-----
> > From:   Andre Lomoy ESMTP:AndreL@SYSDATA.NOA
> > Sent:   Sunday, March 22, 1998 9:09 AM
> > To:     CryptoAPI@DISCUSS.MICROSOFT.COM
> > Subject:        Need help with CryptExportKey
> >
> > I'm trying to export a public key blob, but have run into troubles
> > already at getting the length of the blob.
> > This code gives me a blob length of 84, and an error code 234:
> >
> >     'Attempt to get blob size
> >     If Not CBool(CryptExportKey(lHSignKey, 0, PUBLICKEYBLOB, 0,
> ByVal
> > vbNullChar, lBlobLen)) Then
> >         MsgBox "Failed to get blob size (" & Err.LastDllError & ")",
> > vbCritical, "CryptExportKey"
> >         GoTo ExitFunction
> >     End If
> >
> > Please tell me what I am doing wrong.
> >
> > Also, I'm not sure what datatypes to use: Is it correct to export
> the
> > blob to an array of type Byte?
> > Can all blob types be saved as text files?
> >
> >
> > I would be grateful if someone could send me a list of the error
> > constants (WinErr.h ?).
> > (Any sample code (VB) on using CryptExportKey would of course help a
> > lot
> > too.)
> >
> > Thanks in advance
> >
> > Andre
> >
> > ----------------------------------------------------------------
> > Users Guide
> http://www.microsoft.com/sitebuilder/resource/mailfaq.asp
> > contains important info including how to unsubscribe.  Save time,
> > search
> > the archives at http://microsoft.ease.lsoft.com/archives/index.html
>
> ----------------------------------------------------------------
> Users Guide http://www.microsoft.com/sitebuilder/resource/mailfaq.asp
> contains important info including how to unsubscribe.  Save time,
> search
> the archives at http://microsoft.ease.lsoft.com/archives/index.html

----------------------------------------------------------------
Users Guide http://www.microsoft.com/sitebuilder/resource/mailfaq.asp
contains important info including how to unsubscribe.  Save time, search
the archives at http://microsoft.ease.lsoft.com/archives/index.html

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic