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?