EldoS | Feel safer!

Software components for data protection, secure storage and transfer

ElRSAPublicKeyCrypto.InputEncoding

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
#2243
Posted: 02/12/2007 07:44:30
by Matthew Jones (Standard support level)
Joined: 02/06/2007
Posts: 26

Can you explain what the expectation for ElRSAPublicKeyCrypto.InputEncoding is please? I ask because I thought it would be good to get the results of the encryption as base64, which I can do, but when I set the input as base64 for decoding it fails saying there is too much data. This is right, but that's because it isn't taking into account the base64 encoding making it larger. It needs to decode it first, then make the decision on size.

I'll look for a decode method to use in advance, but right now this is an anomoly.

Thanks, Matthew
#2244
Posted: 02/12/2007 08:00:05
by Ken Ivanov (EldoS Corp.)

InputEncoding is used to specify the encoding of *input* data. If you need to *produce* base64-enveloped data, please consider using OutputEncoding property instead.
#2245
Posted: 02/12/2007 08:27:40
by Matthew Jones (Standard support level)
Joined: 02/06/2007
Posts: 26

I realise it is for input data, but that's what the output of the encryption is, surely? That is, I encrypt and get the Outputdata format as base64, and then to decrypt I feed that same resulting string to the decrypt with Inputdata as base64. I've now found the Base64DecodeString function in SBUtils so I can do it manually anyway, but the output of the encryptor isn't compatible with the decryptor when base64 is used at the moment. (This may just be the RSA or public key problem not allowing encryption bigger than key size, so may not be common. Plus I do have an easy workaround).

Matthew
#2246
Posted: 02/12/2007 08:44:39
by Ken Ivanov (EldoS Corp.)

Quote
but the output of the encryptor isn't compatible with the decryptor when base64 is used at the moment.

The following code (Delphi) does work fine for us:
Code
  Crypto := TElRSAPublicKeyCrypto.Create();
  Crypto.KeyMaterial := KeyMaterial;
  Crypto.InputEncoding := pkeBinary;
  Crypto.OutputEncoding := pkeBase64;

  // encrypting data
  SetLength(InBuf, 33);
  SBRndGenerate(@InBuf[0], Length(InBuf));
  EncSize := 0;
  Crypto.Encrypt(@InBuf[0], Length(InBuf), nil, EncSize);
  SetLength(EncBuf, EncSize);
  Crypto.Encrypt(@InBuf[0], Length(InBuf), @EncBuf[0], EncSize);

  // decrypting encrypted data
  Crypto.InputEncoding := pkeBase64;
  Crypto.OutputEncoding := pkeBinary;
  DecSize := 0;
  Crypto.Decrypt(@EncBuf[0], EncSize, nil, DecSize);
  SetLength(DecBuf, DecSize);
  Crypto.Decrypt(@EncBuf[0], EncSize, @DecBuf[0], DecSize);
#2248
Posted: 02/12/2007 11:11:14
by Matthew Jones (Standard support level)
Joined: 02/06/2007
Posts: 26

What happens if you set your InBuf to just over half your key length? I suspect you'll get the error I talk of. The key is that the code checks that the input data is less than the key length. When base64 encoded, it naturally "doubles" in length, so you can now only handle half the amount of data due to this check. (Obviously the exact amount isn't double due to the encoding but you know what I mean.) For 33 bytes, the check won't trigger and all will be well. My test data is obviously marginal. Using binary, it works as yours. Using base64 it trips over.

Matthew
#2249
Posted: 02/12/2007 11:41:49
by Eugene Mayevski (EldoS Corp.)

It would be great if you could explain the actual problem clearly. As I read the whole description, I got to the point where I got totally confused with it. I don't think Innokentiy does either.


Sincerely yours
Eugene Mayevski
#2250
Posted: 02/12/2007 11:49:50
by Eugene Mayevski (EldoS Corp.)

But don't worry - I've added a task to TODO list to check how the code works with data sizes of 80 bytes in binary, encoded to base64


Sincerely yours
Eugene Mayevski
#2251
Posted: 02/12/2007 11:57:00
by Ken Ivanov (EldoS Corp.)

Quote
What happens if you set your InBuf to just over half your key length?

The above code will work. And it does.

Would you be so kind to provide us some data we can use to reproduce the issue you are reporting?
#2252
Posted: 02/12/2007 13:50:32
by Matthew Jones (Standard support level)
Joined: 02/06/2007
Posts: 26

As is often the way when trying to get things to work, I've changed my code a lot to do the assymetrical bit now, but I've tried to get yours to work so I can make it the same and show the error. But I need to know the variables definitions as I get an internal error using my guesses:

Code
var
   DecBuf : array of char;
   DecSize : Integer;
   EncSize : Integer;
   EncBuf : array of char;
   InBuf : array of char;
   Crypto : TElRSAPublicKeyCrypto;


If I could get that to work, I'm sure I'll be able to demonstrate it. FWIW, the data I'm currently encrypting is "This is the string to be encrypted".

Actually, while I'd like to be able to repeat your demo, I wonder if the real problem is actually related to something I found later. Hmm. The base64 output was copied to my data using a method that ended up adding an extra byte. I wonder if that is the real reason - the base64 decoding was failing, and leaving the output length unchanged. That probably blew the decrypt away. Maybe I caused the problem with my accidental data corruption.

Matthew
#2254
Posted: 02/12/2007 13:55:01
by Ken Ivanov (EldoS Corp.)

We use the following declarations:
Code
var
  Crypto : TElRSAPublicKeyCrypto;
  KeyMaterial : TElRSAKeyMaterial;
  InBuf, EncBuf, DecBuf : ByteArray;
  EncSize, DecSize : integer;

Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.

Reply

Statistics

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