Convert RSA keys from LockBox 2 to LockBox 3

842 Views Asked by At

I convert our project from Delphi 5 to XE4. I used LockBox 2 in Delphi 5. Now I want to use LockBox 3, but I have some RSA keys (generated in LockBox 2). I can't load this keys in LockBox 3. I looked for some info about LockBox 2. I found that LockBox 2 use ASN.1 format for saving keys. Is it true? I can't find which format use LockBox 3. Is there any way to convert private and public keys from ASN.1 to format which use LockBox 3?

Use in Delphi 5 (LockBox 2):

PrivateRSAKey: TLbRSAKey;
MemStream: TMemoryStream; 
...
PrivateRSAKey.LoadFromStream(MemStream);
...
Result := RSAEncryptString(CryptedText, PrivateRSAKey, false); //works fine

Use in XE4 (LockBox 3):

Codec: TCodec;
Key: TSymetricKey;
MemStream: TMemoryStream; //contains same data as MemStream in Delphi 5
...
Key := Codec.Asymetric_Engine.CreateFromStream(MemStream, [partPrivate]);
Codec.InitFromKey(Key);
...
Codec.DecryptStream(DecryptStream, CryptStream); //CryptedStream contains same data as CryptedText in Delphi 5
  //Now DecryptStream contains different data as Result in Delphi 5
0

There are 0 best solutions below