Import a Public key from somewhere else to CngKey?

前端 未结 4 645
面向向阳花
面向向阳花 2020-11-29 06:31

I am looking for a cross platform way to share public keys for ECDSA signing. I had a great thing going from a performance perspective with CngKey and the standard .NET cry

4条回答
  •  误落风尘
    2020-11-29 07:33

    You convert EC key to BCRYPT_ECCKEY_BLOB by like this. We should ignore the first byte from EC key because it just represent compressed/uncompressed format.

    BCRYPT_ECCKEY_BLOB eccBlobHeader;
    PCHAR bycrtptKey;
    eccBlobHeader.dwMagic = BCRYPT_ECDH_PUBLIC_P384_MAGIC;  
    eccBlobHeader.cbKey = 48;//size of EC key(without 1st byte)
    memcpy(bycrtptKey, &eccBlobHeader, 8);//copying 8bytes header blob
    memcpy(bycrtptKey+ 8,publicKeyFromOtherParty+1,publicKeyFromOtherPartySize- 1);
    

    now use bycrtptKey for importing.

提交回复
热议问题