Maximum encryption length

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Maximum encryption length

Bertram Scharpf
Hi,


  $ wc -c xxx
  118 xxx
  $ openssl rsautl -encrypt -certin <some.crt -in xxx
  RSA operation error
  5747:error:0406D06E:rsa routines:RSA_padding_add_PKCS1_type_2:data too large for key size:rsa_pk1.c:151:


With 117 Bytes it works here. How can I generally determine
what is the maximum a key is capable of?

Thanks in advance,

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Maximum encryption length

Goetz Babin-Ebell
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bertram Scharpf wrote:
> Hi,
Hello Bertram,

>   $ wc -c xxx
>   118 xxx
>   $ openssl rsautl -encrypt -certin <some.crt -in xxx
>   RSA operation error
>   5747:error:0406D06E:rsa routines:RSA_padding_add_PKCS1_type_2:data too large for key size:rsa_pk1.c:151:
>
> With 117 Bytes it works here. How can I generally determine
> what is the maximum a key is capable of?

Encrypting data directly with rsa has some security issues you have to
understand unless you compromise the security of the key.

With other words:
If you can't figure out by yourself the maximum length of data you can
encrypt with a given key using the rsautl comand,
you shouldn't use it to encrypt data.

You should use the openssl smime command.


It seems to be adviseable to remove the encrypt/decrypt subcommands
for the rsautl command in a future openssl version.
Those that can use it, can build a special command for this
functionality, all other shouldn't even know that you can use
rsa directly to encrypt data.

Bye

Goetz
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFFxKTK2iGqZUF3qPYRArxpAJ0XlGLEB8y9++oT1dMuIc0zE7xVgQCcDlAx
fbfgsRbNnsf2hd2IdnH/giQ=
=MZ10
-----END PGP SIGNATURE-----
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Maximum encryption length

Bertram Scharpf
Hi Goetz,

Am Samstag, 03. Feb 2007, 16:05:46 +0100 schrieb Goetz Babin-Ebell:

> Bertram Scharpf wrote:
> >   $ wc -c xxx
> >   118 xxx
> >   $ openssl rsautl -encrypt -certin <some.crt -in xxx
> >   RSA operation error
> >   5747:error:0406D06E:rsa routines:RSA_padding_add_PKCS1_type_2:data too large for key size:rsa_pk1.c:151:
> >
> > With 117 Bytes it works here. How can I generally determine
> > what is the maximum a key is capable of?
>
> Encrypting data directly with rsa has some security issues you have to
> understand unless you compromise the security of the key.

O, yes, I would like to understand them.

> If you can't figure out by yourself the maximum length of data you can
> encrypt with a given key using the rsautl comand,
> you shouldn't use it to encrypt data.

So what do I have to read?

> You should use the openssl smime command.

I'm using Ruby; S/MIME seems to be rather young here. At
least it is hidden properly well. I just found it.

Thanks so far,

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Maximum encryption length

Goetz Babin-Ebell
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bertram Scharpf wrote:
> Hi Goetz,
Hi Bertram,

> Am Samstag, 03. Feb 2007, 16:05:46 +0100 schrieb Goetz Babin-Ebell:
>> Bertram Scharpf wrote:
>>>   $ wc -c xxx
>>>   118 xxx
>>>   $ openssl rsautl -encrypt -certin <some.crt -in xxx
>>>   RSA operation error
>>>   5747:error:0406D06E:rsa routines:RSA_padding_add_PKCS1_type_2:data too large for key size:rsa_pk1.c:151:

>> If you can't figure out by yourself the maximum length of data you can
>> encrypt with a given key using the rsautl comand,
>> you shouldn't use it to encrypt data.
>
> So what do I have to read?

Most mortals (including me) don't want to directly encrypt data with the
RSA key but use a combined asymetric/symetric encription.

The programming interface for that is the EVP- interface of OpenSSL

>> You should use the openssl smime command.
>
> I'm using Ruby; S/MIME seems to be rather young here. At
> least it is hidden properly well. I just found it.

SMIME is basically PKCS#7 with some aditionally data,
so you find the related info in the OpenSSL pkcs7 interface.

Bye

Goetz
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFFxPSs2iGqZUF3qPYRAlOlAJ4ogr1MmBzv6YYBnKyTF+iagecN7QCeODw9
qS2Xgcc605tyqUfMmIyF5Vw=
=dTJM
-----END PGP SIGNATURE-----
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Maximum encryption length [SOLVED]

Bertram Scharpf
Hi Goetz,

Am Samstag, 03. Feb 2007, 21:46:36 +0100 schrieb Goetz Babin-Ebell:
> >> You should use the openssl smime command.
> >
> > I'm using Ruby; S/MIME seems to be rather young here. At
> > least it is hidden properly well. I just found it.
>
> SMIME is basically PKCS#7 with some aditionally data,
> so you find the related info in the OpenSSL pkcs7 interface.

I omit signing, the file won't be sent by mail. I'm doing
this in Ruby with success:

  key_crt = OpenSSL::X509::Certificate.new "-----BEGIN CERTIFICATE..."
  key_pem = OpenSSL::PKey::RSA.new "-----BEGIN RSA PRIVATE KEY..."

  p7enc = OpenSSL::PKCS7::encrypt( [key_crt], original)
  encrypted = OpenSSL::PKCS7.write_smime( p7enc)

  p7dec = OpenSSL::PKCS7::read_smime( encrypted)
  decrypted = p7dec.decrypt( key_pem, key_crt)

  if decrypt != original then ....

The command line version of this is:

  openssl smime -encrypt -in original -out encrypted some.crt
  openssl smime -decrypt -in encrypted -out decrypted -inkey some.pem some.crt

Thanks.

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]