简体   繁体   中英

How do i create/use an IBuffer?

I want to use functions of the Winapi.Security.Cryptography.Core_IAsymmetricKeyAlgorithmProvider and it has a parameter of type IBuffer . i dont know how to use an IBuffer or how to give data to it.

i tried allocationg memory and giving the function a pwide char but the ide already told me this wont work. I also didnt find anything useful online.

Winapi.Security.Cryptography contains wrappers for Windows.Security.Cryptography.Core (Windows UWP)

Check this page first: https://learn.microsoft.com/en-us/uwp/api/windows.security.cryptography.core.asymmetrickeyalgorithmprovider?view=winrt-22621

There is a C# app example that demonstrates how to use this interface. Details about IBuffer can be found on this page:

https://learn.microsoft.com/en-us/uwp/api/windows.storage.streams.ibuffer?view=winrt-22621

This is probably your first step, if you want encrypt with RSA PKCS1:

uses
  System.Win.WinRT,
  Winapi.WinRT,      
  Winapi.Security.Cryptography,
  Winapi.Storage.Streams;
const
  KeyLength = 512;
var 
  objAlgProv: Core_IAsymmetricKeyAlgorithmProvider;
  data: TBytes;
  cleardata, encrypted: IBuffer;
  key: Core_ICryptographicKey;
  hs: HSTRING;
  EncryptedBase64: string;
begin
  data := TEncoding.UTF8.GetBytes('clear text');
  objAlgProv := TCore_AsymmetricKeyAlgorithmProvider.OpenAlgorithm(TCore_AsymmetricAlgorithmNames.RsaPkcs1);
  key := objAlgProv.CreateKeyPair(KeyLength);
  cleardata := TCryptographicBuffer.CreateFromByteArray(length(data), @data[0]);
  encrypted := TCore_CryptographicEngine.Encrypt(key, cleardata, nil {IV});
  hs := TCryptographicBuffer.EncodeToBase64String(encrypted); 
  EncryptedBase64 := TWindowsString.HStringToString(hs);
end;

If you have further trouble translating the solution into Delphi, show your code an explain the details what you need to know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM