Encoding with SHA-512

Discussion of open issues, suggestions and bugs regarding network security and data protection solution - SecureBridge
Post Reply
Spbob1
Posts: 2
Joined: Sat 14 Apr 2018 06:53

Encoding with SHA-512

Post by Spbob1 » Sun 15 Apr 2018 19:32

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!

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Encoding with SHA-512

Post by ViktorV » Mon 16 Apr 2018 10:59

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:

Code: Select all

var
Cert: TScCertificate;
...
Cert := TScCertificate.Create(ScFileStorage.Certificates);
Cert.CertName := 'CertName';
Cert.ImportFrom(AFileName, APwd);
ScCMSProcessor.Storage := ScFileStorage;
ScCMSProcessor.CertificateName := 'CertName';
Also, you can use the TScCMSProcessor.Certificate property to specify the certificate. For example:

Code: Select all

ScCMSProcessor.Certificate := Cert;
So, to solve your task, you should set the CMSProcessor.CertificateName (CMSProcessor.Certificate) property in your sample to the correct value.
Last edited by ViktorV on Tue 17 Apr 2018 13:12, edited 1 time in total.

Spbob1
Posts: 2
Joined: Sat 14 Apr 2018 06:53

Re: Encoding with SHA-512

Post by Spbob1 » Tue 17 Apr 2018 12:10

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!

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Encoding with SHA-512

Post by ViktorV » Tue 17 Apr 2018 13:52

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').

Post Reply