EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Using RSACryptoServiceProvider public key in ElRSAPublicKeyCrypto

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#1952
Posted: 01/02/2007 08:59:20
by Debbie Croft (Basic support level)
Joined: 01/02/2007
Posts: 3

I have a .NET application uses RSACryptoServiceProvider to produce a private/public keypair. I'd like to use ElRSAPublicKeyCrypto with that public key to decrypt a file.

How do I import an RSACryptoServiceProvider generated public key for use with ElRSAPublicKeyCrypto?
#1953
Posted: 01/02/2007 10:59:48
by Eugene Mayevski (EldoS Corp.)

1) Public keys are used to encrypt the data. Private keys are used to decrypt it.
2) You can't (in 99,9999% of cases) encrypt the file with an RSA key. So there must be some format behind the encrypted file. For example, PKCS#7. Or some custom format.


Sincerely yours
Eugene Mayevski
#1957
Posted: 01/03/2007 05:12:20
by Debbie Croft (Basic support level)
Joined: 01/02/2007
Posts: 3

I'm actually going to encrypt a short passphrase using RSA. That passphrase will be used with AES to encrypt the contents of the file.

My challenge is that I need to use a public key in my Delphi app that has been generated by the .NET RSACryptoServiceProvider object. Is this possible using ElRSAPublicKeyCrypto? Can ElRSAPublicKeyCrypto read public keys generated by ElRSAPublicKeyCrypto?
#1965
Posted: 01/03/2007 07:57:57
by Ken Ivanov (EldoS Corp.)

Would it be a better solution for you to take a look at TElMessageEncryptor/TElMessageDecryptor classes? These classes allow to encrypt/decrypt large amounts of data (e.g., files) either with X.509 certificates or with generic keys (e.g., passwords).

TElRSAPublicKeyCrypto accesses RSA key material using TElRSAKeyMaterial object. I.e., (a) you should load public/private key material from some key storage (memory, file, Win32 system store) into the TElRSAKeyMaterial object, and (b) bind this object to TElRSAPublicKeyCrypto instance. If the public/private key is stored in memory, please consider using TElRSAKeyMaterial.LoadPublic()/LoadSecret() methods. If the key is stored in Win32 system store (as X.509 certificate), please consider using TElWinCertStorage object to access the list of certificates and TElX509Certificate.KeyMaterial property to access the corresponding key material object.
#1968
Posted: 01/03/2007 09:46:24
by Ken Ivanov (EldoS Corp.)

Please use the following code to import secret key material to the TElRSAKeyMaterial object:
Code
private TElRSAKeyMaterial RSAParametersToKeyMaterial(RSAParameters rsa)
{
        byte[] pm = rsa.Modulus;
   byte[] pe = rsa.Exponent;
   byte[] pd = rsa.D;
   byte[] p = rsa.P;
   byte[] q = rsa.Q;
   byte[] dp = rsa.DP;
   byte[] dq = rsa.DQ;
   byte[] u = rsa.InverseQ;
   TElRSAKeyMaterial result = new TElRSAKeyMaterial();
   byte[] keyBlob = null;
   int keyBlobSize = 0;
   result.EncodePrivateKey(pm, 0, pm.Length, pe, 0, pe.Length, pd, 0, pd.Length,
      p, 0, p.Length, q, 0, q.Length, dp, 0, dp.Length, dq, 0, dq.Length,
      u, 0, u.Length, ref keyBlob, 0, ref keyBlobSize);
   keyBlob = new byte[keyBlobSize];
   result.EncodePrivateKey(pm, 0, pm.Length, pe, 0, pe.Length, pd, 0, pd.Length,
      p, 0, p.Length, q, 0, q.Length, dp, 0, dp.Length, dq, 0, dq.Length,
      u, 0, u.Length, ref keyBlob, 0, ref keyBlobSize);
   result.LoadSecret(keyBlob, 0, keyBlobSize);
         return result;
}
Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.

Reply

Statistics

Topic viewed 4034 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!