Hello!
Sorry because I'm very new in SB and area of securing-coding.
I would like to encoding a string (by SHA-512) using TscCMSProcessor.
My code:
CMSProcessor.CertificateName:='SHA_512';
in_stream:=TSTringStream.Create('this string for code');
out_stream:=TStringStream.Create('');
CMSProcessor.EncodeData(in_stream,out_stream,ceSMIME);
The DigestAgorithm property is set to haSHA2_512.
Nothing success.
My questions:
Is this the right component for this?
Is EncodeData the right method to solve this?
I don't know, what value is right at the CertificateName property.
Can I find a few example in this theme in Devart's page?
Thank You for your help and sorry for my pour english!
Encoding with SHA-512
Re: Encoding with SHA-512
The TScCMSProcessor component is suitable for solving your task. For the correct operation of the specified code, please use our recommendation:
- before any operation the Certificate or CertificateName property should be set.
To use the certificate, you just need to specify it in the TScCMSProcessor.CertName property, pre-importing it in TScStorage. You can do this either at designtime using the Certificates tab in the property editor of the TScStorage component descedant, or at runtime using the method TScCertificate.ImportFrom(Stream: TStream; const Password: string = ''). For example:Also, you can use the TScCMSProcessor.Certificate property to specify the certificate. For example:
So, to solve your task, you should set the CMSProcessor.CertificateName (CMSProcessor.Certificate) property in your sample to the correct value.
- before any operation the Certificate or CertificateName property should be set.
To use the certificate, you just need to specify it in the TScCMSProcessor.CertName property, pre-importing it in TScStorage. You can do this either at designtime using the Certificates tab in the property editor of the TScStorage component descedant, or at runtime using the method TScCertificate.ImportFrom(Stream: TStream; const Password: string = ''). For example:
Code: Select all
var
Cert: TScCertificate;
...
Cert := TScCertificate.Create(ScFileStorage.Certificates);
Cert.CertName := 'CertName';
Cert.ImportFrom(AFileName, APwd);
ScCMSProcessor.Storage := ScFileStorage;
ScCMSProcessor.CertificateName := 'CertName';
Code: Select all
ScCMSProcessor.Certificate := Cert;
Last edited by ViktorV on Tue 17 Apr 2018 13:12, edited 1 time in total.
Re: Encoding with SHA-512
Thank you for answer!
I tried to run this code, but I got an error : "wrong certificate context"
Cert:=TScCertificate.Create(Form2.ScFileStorage.Certificates);
Cert.CertName:='CertName';
Cert.ImportFrom('MyCert.CRT','psw');
Cert.Ready:=True;
Form2.ScCMSProcessor.Storage:=Form2.scFileStorage;
Form2.ScCMSProcessor.CertificateName:='CertName';
I don't know, what text has to be in MyCert.CRT file, because now it is empty.
Is this has a fix structure? I only found files with complicated text in.
But what must contain in my case?
And what about the password? This could be empty in my case?
The using of Certificate necessary for a simple encoding a string with SHA-512 algorithm?
Thank You for help!
I tried to run this code, but I got an error : "wrong certificate context"
Cert:=TScCertificate.Create(Form2.ScFileStorage.Certificates);
Cert.CertName:='CertName';
Cert.ImportFrom('MyCert.CRT','psw');
Cert.Ready:=True;
Form2.ScCMSProcessor.Storage:=Form2.scFileStorage;
Form2.ScCMSProcessor.CertificateName:='CertName';
I don't know, what text has to be in MyCert.CRT file, because now it is empty.
Is this has a fix structure? I only found files with complicated text in.
But what must contain in my case?
And what about the password? This could be empty in my case?
The using of Certificate necessary for a simple encoding a string with SHA-512 algorithm?
Thank You for help!
Re: Encoding with SHA-512
To encode and sign the data in the CMS protocol, you need a certificate. You can create it by yourself using different tools or buy it. For more information about obtaining a certificate, you can ask the appropriate question at the specialized forums.
After receiving the certificate, you should import it using the TScCertificate.ImportFrom method. For example, Cert.ImportFrom ('MyCert.CRT').
After receiving the certificate, you should import it using the TScCertificate.ImportFrom method. For example, Cert.ImportFrom ('MyCert.CRT').