I am trying to generate keys and export them, but that doesn't really work, can you tell me what I'm doing wrong? I generate it like this:

var Prov: HCRYPTPROV; ExchangeKey, SignKey: HCRYPTKEY; begin CryptAcquireContext(@Prov,'My_Container',nil,PROV_RSA_FULL,CRYPT_NEWKEYSET); CryptGenKey(Prov,AT_KEYEXCHANGE,0,@ExchangeKey); CryptGenKey(Prov,AT_SIGNATURE,0,@SignKey); CryptDestroyKey(SignKey); CryptDestroyKey(ExchangeKey); CryptReleaseContext(Prov,0); 

and export

 var Prov: HCRYPTPROV; SignKey: HCRYPTKEY; Stream: TMemoryStream; BufSize: DWORD; ExchangeKey: HCRYPTKEY; begin CryptAcquireContext(@Prov,'My_Container',nil,PROV_RSA_FULL,0); CryptGetUserKey(Prov,AT_SIGNATURE,@SignKey); Stream:=TMemoryStream.Create; CryptExportKey(SignKey,0,PUBLICKEYBLOB,0,nil,@BufSize); Stream.SetSize(BufSize); CryptExportKey(SignKey,0,PUBLICKEYBLOB,0,PByte(Stream.Memory),@BufSize); Stream.SaveToFile('fiile.txt'); Stream.Free; CryptDestroyKey(SignKey); CryptReleaseContext(Prov,0); end; 

but as a result I get

$ RSA1 ™ Ё4ЕI,, ¤ · њ џ џ џ јѓ јѓ јѓ ¦ ¦ € € г »4 4 4 4 љ 4 ™ ry¤dў * a

not particularly similar to the key, and it is always the same, can you poke your nose, what am I doing wrong?

  • one
    Not so - you do not check the return status from the API. "not really like the key" is what you think, in fact it looks like a public key blob. - Vladimir Martyanov
  • can you help fix it? - Lolidze
  • I do not write and I will not write on Delphi - Vladimir Martyanov
  • Add a question - in what format you want to get the public key. Well, besides the comment of Vladimir Martyanov on non-checking the status of the return of functions, you destroy the key before using it .... - kami

0