leolui

Member since: Tuesday, 06 June 2017
Last login: 2 months ago
Profile viewed: 95 views

No Rank
Points: 0

leolui replied to the topic 'Any mobile version QR code generator support unicode?' in the forum. 2 months ago

If it is caused by incorrect creation of QRCode, can it being corrected? I cannot control what barcode scanner the mobile user will be used.

Read More...

leolui created a new topic ' Any mobile version QR code generator support unicode?' in the forum. 2 months ago

I try Žarko Gajić DelphiZXingQRCode for XE5 FMX version in my Tokyo 10.2.3 version by entering some Chinese characters, but the QR Code generated is wrong. The generated QR code cannot being scanned correctly, the scanning result doe not match with the original text. Any suggestion for a QR Code generator that support Unicode?

Read More...

leolui thanked haruyuki mohri in topic Azure Cosmos DB signature 3 months ago
leolui replied to the topic 'Azure Cosmos DB signature' in the forum. 4 months ago

I discovered using System.Hash can write less codes.

uses
System.Hash;
...

function GenerateCosmosDBSignature(const AData, AKey: string): string;
var
keyBytes, dataBytes: TBytes;

begin

keyBytes:=TNetEncoding.Base64.DecodeStringToBytes(AKey);
dataBytes:=TEncoding.UTF8.GetBytes(AData);

result:= AnsiString(TNetEncoding.Base64.EncodeBytesToString(THashSHA2.GetHMACAsBytes(dataBytes, keyBytes)));

end;

Read More...

leolui replied to the topic 'Azure Cosmos DB signature' in the forum. 5 months ago

After searching all possible websites and a lot of trial and error, I get the solution finally. The result is same as the signature generated from C#. The code was modified from

function GenerateCosmosDBSignature(const AData, AKey: string): string;
var
AHMAC: TIdBytes;
bytes: TBytes;

begin
IdSSLOpenSSL.LoadOpenSSLLibrary;

if not TIdHashSHA256.IsAvailable then
raise Exception.Create('SHA-256 hashing is not available!');

with TIdHMACSHA256.Create do
try
//original
//Key := IndyTextEncoding_UTF8.GetBytes(AKey);
//AHMAC := HashValue(IndyTextEncoding_UTF8.GetBytes(AData));

//after modified
Key := TIdBytes(TNetEncoding.Base64.DecodeStringToBytes(AKey));
AHMAC := HashValue(IndyTextEncoding_UTF8.GetBytes(AData));

finally
Free;
end;

//original
//result := TIdEncoderMIME.EncodeBytes(AHMAC);

//after modified
result:= AnsiString(TNetEncoding.Base64.EncodeBytesToString(System.TArray<System.Byte>(AHMAC)));

end;

Read More...

leolui created a new topic ' Azure Cosmo DB signature' in the forum. 5 months ago

My project needs to connect the Azure Cosmo DB by REST API.
The Azure Cosmo DB connection requires to pass a HMACSHA256 signature to
the HTTP header. I tried to use THashSHA2.GetHMAC(Data, Key) function to get
this signature. But when I compare the result with the signature I take from C# code
(the example code in Azure webpage), they are not the same. In the C# code I saw
it converts the key to Base64String before calculating the signature.
Should I do the same step in Delphi? How to do it? Do anyone have the experience
doing the Azure Cosmo DB signature calculation?

Read More...