HASH String
HASH String
Hello, 
I just want to know if it is possible to import one RSA Private Key and
hash one string with TScKey. For example "FAC001:10-10-12T20:20:15"
would give a signed string Base64 with 172 length, something like "Am2K6+BP5....mgc/gpu=".. is it possible ? and if yes could you please give-me just an small example code, because I had already searched and found nothing.
Thank you,
			
									
									
						I just want to know if it is possible to import one RSA Private Key and
hash one string with TScKey. For example "FAC001:10-10-12T20:20:15"
would give a signed string Base64 with 172 length, something like "Am2K6+BP5....mgc/gpu=".. is it possible ? and if yes could you please give-me just an small example code, because I had already searched and found nothing.
Thank you,
The TScKey class lets you generating new keys by using the Generate method. To import or save a key in one of formats, you should use the ImportFrom or ExportTo methods correspondingly. 
The TScKey lets you to sign data with the private key and verify signature with the public key by using the Sign and VerifySign methods. Also TScKey can encrypt and decrypt data with Encrypt and Decrypt methods.
			
									
									
						The TScKey lets you to sign data with the private key and verify signature with the public key by using the Sign and VerifySign methods. Also TScKey can encrypt and decrypt data with Encrypt and Decrypt methods.
Code: Select all
var
  Key: TScKey;
  buf, res: TBytes;
  s: string;
begin
  Key.Ready := True;
  s := 'FAC001:10-10-12T20:20:15';
  SetLength(buf, Length(s));
  Move(s[1], buf[0], Length(s));
  res := Key.Encrypt(buf);
  res := Key.Sign(res);
end;This was introduced by the Portugal General Directorate of Taxes and they said we could use openssl to generate Private and Public keys, and hash some lines on the Billing documents.
So we generated Private and Public Keys with it, and wanted to work with SecureBridge components to hash that lines.
The Private Key its something like "-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKB....wm-----END RSA PRIVATE KEY-----"
and when we try to import on SecureBridge Demo Application it works, but when I try to import on a new project it raises an Exception - Access Violation.
Do we need to create TSckey first ? we just declare the variable Key and then try to import the key on it. it is necessary to use the TscFileStorage?
thanks for your support,
			
									
									
						So we generated Private and Public Keys with it, and wanted to work with SecureBridge components to hash that lines.
The Private Key its something like "-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKB....wm-----END RSA PRIVATE KEY-----"
and when we try to import on SecureBridge Demo Application it works, but when I try to import on a new project it raises an Exception - Access Violation.
Do we need to create TSckey first ? we just declare the variable Key and then try to import the key on it. it is necessary to use the TscFileStorage?
thanks for your support,
I'm sorry to post again, 
but even when we generate they Key without import it raises an execption,
Here's what we are doing,
var Algorithm : TScAsymmetricAlgorithm;
Key: TScKey;
buf, res: TBytes;
s: string;
begin
Algorithm := aaRSA;
Key.Generate(Algorithm, 1024);
Key.Ready := True;
s := 'FAC001:10-10-12T20:20:15';
SetLength(buf, Length(s));
Move(s[1], buf[0], Length(s));
res := Key.Encrypt(buf);
res := Key.Sign(res);
end;
			
									
									
						but even when we generate they Key without import it raises an execption,
Here's what we are doing,
var Algorithm : TScAsymmetricAlgorithm;
Key: TScKey;
buf, res: TBytes;
s: string;
begin
Algorithm := aaRSA;
Key.Generate(Algorithm, 1024);
Key.Ready := True;
s := 'FAC001:10-10-12T20:20:15';
SetLength(buf, Length(s));
Move(s[1], buf[0], Length(s));
res := Key.Encrypt(buf);
res := Key.Sign(res);
end;
Yes, it is correct. RSA cryptoalgorithm adds random padding to the data being encrypted for strong encryption. But on decrypting you will always get the same correct result.RuiSilva wrote:Every time we encrypt one string it gives us diferent outputs, even if we generate or import the key, is this normal ?
To encode/decode data to the Base64 format you can use the TBase64 class of the ScBase64 unit. This class releases the following methods:RuiSilva wrote:By the way does Secure Bridge has any option to encode String on Base64 ?
Code: Select all
  class function Encode(const data: TBytes): TBytes;
  class function Decode(const data: TBytes): TBytes;