EldoS | Feel safer!

Software components for data protection, secure storage and transfer

probleme for signfile in c#

Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.
#17721
Posted: 10/04/2011 11:06:33
by Bruno Penguilly (Standard support level)
Joined: 09/30/2011
Posts: 12

Hello,
i've got a little problem in c#.
With this code i cant sign file
with same code i can sign file in pascal (with delphi xe).

Code
TElPKCS11SlotInfo SlotInfo;
TElPKCS11CertStorage Storage;
TElMemoryCertStorage CertStorage;
TElPKCS11SessionInfo Session;
TElX509Certificate cert;
TElRSAPublicKeyCrypto signature;






  public void openstorage()
          {

SBUtils.Unit.SetLicenseKey("my key");
              Storage = new TElPKCS11CertStorage();
              Storage.DLLName = "eTPKCS11.dll";

          
              try
              {
                  Storage.Open();
              }
              catch (Exception E)
              {
                  Storage.Dispose();
                  if (E.Message.IndexOf("SecureBlackbox_PKCS11Proxy") > 0)
                  {
                      MessageBox.Show(E.Message + "\r\n\r\n\r\n" + "SecureBlackbox_PKCS11Proxy.dll is an unmanaged proxy DLL. It can be found in the folder, to which you installed SecureBlackbox. Copy it to the folder in which your executable file is located.");
                  }
                  else
                      MessageBox.Show("Error opening storage: " + "eTPKCS11.dll" + "\r\n" + E.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                  return;
              if (!Storage.Module.get_Slot(0).TokenPresent)
              {
                  MessageBox.Show("Clé introuvable dans le slot spécifié", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                  return;
              }
              if (Session != null)
              {

                  Session.Logout();
                  Storage.CloseSession(0);
                  Session = null;
              }
              RO = Storage.Module.get_Slot(0).ReadOnly;
              try
              {
                  Session = Storage.OpenSession(0, RO);
              }
              catch
              {
                  if (!RO)
                      Session = Storage.OpenSession(0, true);
                  else
                      throw;
              }
              try
              {
                  Session.Login((int)SBPKCS11Base.Unit.utUser, Password);
              }
              catch
              {
                  Storage.CloseSession(0);
                  Session = null;
              }
              CertStorage = new TElMemoryCertStorage();//creation de linstance de l'objet
              cert = Storage.get_Certificates(0); // chargement du certificat

              signature = new TElRSAPublicKeyCrypto();
              signature. = SBConstants.Unit.SB_ALGORITHM_DGST_SHA256;

              byte[] InBuffer, OutBuffer;
              FileStream Stream;
              FileStream Stream2;
              int InSize, OutSize, res;

              Stream2 = new FileStream(chemsignature, FileMode.CreateNew ,FileAccess.ReadWrite);

              Stream = new FileStream(_chem_import, FileMode.Open, FileAccess.Read);
              try
              {
                  InSize = (int)Stream.Length;
                  InBuffer = new byte[InSize];
                  Stream.Read(InBuffer, 0, InSize);
              }
              finally
              {
                  Stream.Close();
              }
              
              signature.InputEncoding = TSBPublicKeyCryptoEncoding.pkeBinary;
              signature.OutputEncoding = TSBPublicKeyCryptoEncoding.pkeBase64;
              signature.KeyMaterial = cert.KeyMaterial;
              try
              {
                  signature.SignDetached(Stream, Stream2, InSize);
              }
              //res = Signer.Sign(InBuffer, ref OutBuffer, ref OutSize, false);
              catch
              {
                //  MessageBox.Show(String.Format("Error {0} when signing the file"), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                  return;
              }
          }
      }  


if anyone has an idea about my problem I would be grateful.

tank you...
#17722
Posted: 10/04/2011 11:10:49
by Ken Ivanov (EldoS Corp.)

Thank you for contacting us.

Could you please specify the exact problem you are facing? Which exactly call fails, is any exception thrown, ...?
#17723
Posted: 10/04/2011 11:20:22
by Eugene Mayevski (EldoS Corp.)

You have a license only for VCL edition, so I assume that for .NET edition you are using the evaluation license key, aren't you? Your VCL license key won't work in .NET.


Sincerely yours
Eugene Mayevski
#17724
Posted: 10/05/2011 02:17:56
by Bruno Penguilly (Standard support level)
Joined: 09/30/2011
Posts: 12

Delphi to instantiate the signature is made like this:
Signature: = TElRSAPublicKeyCrypto.Create (SB_CERT_ALGORITHM_SHA256_RSA_ENCRYPTION);

what to do with C #, I can find no examples
thank you
#17725
Posted: 10/05/2011 02:35:14
by Vsevolod Ievgiienko (EldoS Corp.)

Hello.

In C# this code will look like

TElPublicKeyCrypto Crypto = new TElRSAPublicKeyCrypto(SBUtils.Unit.SB_CERT_ALGORITHM_SHA256_RSA_ENCRYPTION, null);
#17726
Posted: 10/05/2011 03:21:31
by Bruno Penguilly (Standard support level)
Joined: 09/30/2011
Posts: 12

cool
it's work :o)

Thanks
#17727
Posted: 10/05/2011 04:12:57
by Bruno Penguilly (Standard support level)
Joined: 09/30/2011
Posts: 12

One more quick question.
my signature is different between my project delphi and c #
I think this option Signature.CryptoType = rsapktPKCS1;(in delphi)
but I can't find this option in C #

thank you again
#17728
Posted: 10/05/2011 04:22:01
by Vsevolod Ievgiienko (EldoS Corp.)

Try to re-declare Signature this way:

TElRSAPublicKeyCrypto Signature = new TElRSAPublicKeyCrypto(...);

and then you can use this property:

Signature.CryptoType = SBPublicKeyCrypto.Unit.rsapktPKCS1;

All this information is available in our documentation: http://www.eldos.com/documentation/sb...otype.html
#17729
Posted: 10/05/2011 04:39:17
by Bruno Penguilly (Standard support level)
Joined: 09/30/2011
Posts: 12

thank you
but I still have a difference between my two signatures,
projects appear to be similar.

We would like to buy as soon as the component for C # ,
but I would verify that the generated signatures is similar before.



thank again if you have an idea.
#17730
Posted: 10/05/2011 04:46:19
by Vsevolod Ievgiienko (EldoS Corp.)

Quote
but I still have a difference between my two signatures,

What are the differences?

Try to generate signatures using our Delphi and C# demos and then compare the results. Both signatures will be the same. It seems that you set different options for the TElRSAPublicKeyCrypto in Delphi and C#.

The demos are located in \EldoS\SecureBlackbox.NET\Samples\C#\PKIBlackbox\Primitives folder for C# and \EldoS\SecureBlackbox\Samples\Delphi\PKIBlackbox\Primitives folder for Delphi.

See "SignDetached" and "VerifyDetached" folders.
Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.

Reply

Statistics

Topic viewed 3820 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!