Announcement

Collapse
No announcement yet.

API CryptImportKey & CryptExportKey

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • David Roberts
    replied
    Wow, I'm lucky to get away with it.

    I'll now use:
    Code:
    Type HMAC_Info
      HashAlgid As Dword
      dummy As String * 16
    End Type
    From SDK:
    HashAlgid
    Specifies the hash algorithm to be used.
    pbInnerString
    Pointer to the inner string to be used in the HMAC calculation. The default inner string is defined as the byte 0x36 repeated 64 times.
    cbInnerString
    The count of bytes in pbInnerString. The CSP uses the default inner string if cbInnerString is equal to zero.
    pbOuterString
    Pointer to the outer string to be used in the HMAC calculation. The default outer string is defined as the byte 0x5C repeated 64 times.
    cbOuterString
    The count of bytes in pbOuterString. The CSP uses the default outer string if cbOuterString is equal to zero.
    The 0x36 and 0x5C are from the standard HMAC protocol utilizing the best Hamming distance so I left them alone.

    I read that rather quickly and missed the pointer reference.

    Thanks, José - an incorrect structure size could do untold damage.

    PS The very first code snippet no longer gives an error. Magic!
    Last edited by David Roberts; 16 Nov 2009, 10:15 AM.

    Leave a comment:


  • José Roca
    replied
    In other of your posts, I see that you have defined HMAC_Info as follows:

    Code:
    Type HMAC_Info
      HashAlgid As Dword
      dummy As String * 10
    End Type
    This is wrong. It should be:

    Code:
    TYPE HMAC_INFO
       HashAlgid     AS DWORD      ' ALG_ID  HashAlgid
       pbInnerString AS BYTE PTR   ' BYTE   *pbInnerString
       cbInnerString AS DWORD      ' DWORD   cbInnerString
       pbOuterString AS BYTE PTR   ' BYTE   *pbOuterString
       cbOuterString AS DWORD      ' DWORD   cbOuterString
    END TYPE
    This is the original C++ declaration:

    Code:
    typedef struct _HMAC_Info {
      ALG_ID HashAlgid;
      BYTE * pbInnerString;
      DWORD  cbInnerString;
      BYTE * pbOuterString;
      DWORD  cbOuterString;
    }HMAC_INFO, *PHMAC_INFO;
    pbInnerString and pbOuterString aren't bytes, but byte pointers.

    Leave a comment:


  • David Roberts
    replied
    They are both UDTs
    Code:
    Type PublicKeyStruc
      bType As Byte
      bVersion As Byte
      Reserved As Word
      ALG_ID As Dword
    End Type
    
    Type KeyBlob
      BlobHeader As PublicKeyStruc
      cbData As Dword
      pbData( 1 To 1024 ) As Byte
    End Type
    
    Type HMAC_Info
      HashAlgid As Dword
      dummy As String * 10
    End Type
    > If it is dimmed in the first position maybe it becomes a register variable.

    I must remember that one, José.

    Leave a comment:


  • José Roca
    replied
    And what is KeyBlob? A DWORD, a LONG a pointer? If it is dimmed in the first position maybe it becomes a register variable.

    Leave a comment:


  • David Roberts
    replied
    I don't believe this.
    Code:
    Function PBMain
    Dim OurKeyBlob As KeyBlob
    Dim HMACInfo As HMAC_Info
    caused an error 87 ("The parameter is incorrect") when the UDT HMACInfo was used in a parameter list.

    This
    Code:
    Function PBMain
    Dim HMACInfo As HMAC_Info
    Dim OurKeyBlob As KeyBlob
    solved the problem.

    All I've done is change the Dims order.

    Alignment? Nope - tried Dword - the obvious candidate.

    Why did I change the order? After two days there wasn't much left I could do.

    Now, is anyone going to put me out of my misery or do I have a PB bug on my hands?

    Leave a comment:


  • David Roberts
    started a topic API CryptImportKey & CryptExportKey

    API CryptImportKey & CryptExportKey

    Has anyone messed around with these APIs and, in particular, importing a PLAINTEXTKEYBLOB?
Working...
X