473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Encryption -- Blowfish limited to 8 byte passowrds?

I have no background in encryption, so I'm working with samples I've found
in various places and patching them together. I know Blowfish can use a 56
byte key. The version of this program in Perl has no problem with a 56
byte key, but this Java version has problems if I use a key that is any
length other than 8 bytes. Is there something I can do to enable 56 byte
keys and vectors? Here's what I'm doing:

//byte[] bRawData is already set
String sCryptoKey = "MyOwnKey";
String sCryptoVector = "MyOwnVec";
byte[] bDecrypted;

try {
SecretKeySpec oKey = new SecretKeySpec(sCryptoKey.getBytes("UTF8"),
"Blowfish");
IvParameterSpec oIV = new IvParameterSpec(sCryptoVector.getBytes("UTF8"));
Cipher oCipher = Cipher.getInstance("Blowfish/CBC/PKCS5Padding");
oCipher.init(Cipher.DECRYPT_MODE, oKey, oIV );
//I also have a ENCRYPT_MODE mirror of this routine.
bDecrypted = oCipher.doFinal(bRawData);
} catch (Exception e) {}

Is there a setting I'm missing? Why won't Java allow other length keys and
vectors?

Thanks!

Hal
Jul 17 '05 #1
2 10151
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hal Vaughan wrote:
I have no background in encryption, so I'm working with samples I've
found
in various places and patching them together. I know Blowfish can
use a 56
byte key. The version of this program in Perl has no problem with a
56 byte key, but this Java version has problems if I use a key that
is any
length other than 8 bytes. Is there something I can do to enable 56
byte
keys and vectors? Here's what I'm doing:

//byte[] bRawData is already set
String sCryptoKey = "MyOwnKey";
String sCryptoVector = "MyOwnVec";
byte[] bDecrypted;

try {
SecretKeySpec oKey = new
SecretKeySpec(sCryptoKey.getBytes("UTF8"),
"Blowfish");
IvParameterSpec oIV = new
IvParameterSpec(sCryptoVector.getBytes("UTF8")); Cipher
oCipher = Cipher.getInstance("Blowfish/CBC/PKCS5Padding");
oCipher.init(Cipher.DECRYPT_MODE, oKey, oIV );
//I also have a ENCRYPT_MODE mirror of this routine.
bDecrypted = oCipher.doFinal(bRawData);
} catch (Exception e) {}

Is there a setting I'm missing? Why won't Java allow other length
keys and vectors?

Thanks!

Hal


Hello,
I'm pretty sure this is because you are trying to use the password
itself as underlying key material, and the Blowfish implementation
you're working with (or perhaps the entire algorithm, I'm not
particularly familiar with it) actually operates on 64-bit keys (=8
bytes). See, when you use a SecretKeySpec, that's actually operating
on the underlying key material. When you use a password, the password
itself is not typically used directly. Instead, it passes through
some kind of hash function. This is probably what is happening,
without you knowing it, in Perl. In Java, you have to explicitly
indicate that you want this to happen. The normal way to do this is
to use the javax.crypto.spec.PBEKeySpec class to transform your
password into a key, rather than using SecretKeySpec. This is the
"proper" way to do password-based encryption. This could be slightly
misleading, since irrelevant of the length of the password, the
algorithm itself is only acting on an 8-byte key. Longer passwords
are hashed down to size, so it's possible that there could be more
than one password that successfully decrypts the data. Assuming the
hash function is secure, it is "computationally infeasible" to figure
out what those other passwords are, but they probably exist. This is
always the case when using a password with an algorithm that has a
fixed key size (i.e. almost all of them).

- --
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/mbBDwxczzJRavJYRAuieAJ4t/IvawT18b6Q/dqblg+gveyewpACeKZiS
hIOQIsym9rIfjmlakT3zIZk=
=EsJ4
-----END PGP SIGNATURE-----
Jul 17 '05 #2
Chris wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hal Vaughan wrote:
I have no background in encryption, so I'm working with samples I've
found
in various places and patching them together. I know Blowfish can
use a 56
byte key. The version of this program in Perl has no problem with a
56 byte key, but this Java version has problems if I use a key that
is any
length other than 8 bytes. Is there something I can do to enable 56
byte
keys and vectors? Here's what I'm doing:

//byte[] bRawData is already set
String sCryptoKey = "MyOwnKey";
String sCryptoVector = "MyOwnVec";
byte[] bDecrypted;

try {
SecretKeySpec oKey = new
SecretKeySpec(sCryptoKey.getBytes("UTF8"),
"Blowfish");
IvParameterSpec oIV = new
IvParameterSpec(sCryptoVector.getBytes("UTF8")); Cipher
oCipher = Cipher.getInstance("Blowfish/CBC/PKCS5Padding");
oCipher.init(Cipher.DECRYPT_MODE, oKey, oIV );
//I also have a ENCRYPT_MODE mirror of this routine.
bDecrypted = oCipher.doFinal(bRawData);
} catch (Exception e) {}

Is there a setting I'm missing? Why won't Java allow other length
keys and vectors?

Thanks!

Hal


Hello,
I'm pretty sure this is because you are trying to use the password
itself as underlying key material, and the Blowfish implementation
you're working with (or perhaps the entire algorithm, I'm not
particularly familiar with it) actually operates on 64-bit keys (=8
bytes). See, when you use a SecretKeySpec, that's actually operating
on the underlying key material. When you use a password, the password
itself is not typically used directly. Instead, it passes through
some kind of hash function. This is probably what is happening,
without you knowing it, in Perl. In Java, you have to explicitly
indicate that you want this to happen. The normal way to do this is
to use the javax.crypto.spec.PBEKeySpec class to transform your
password into a key, rather than using SecretKeySpec. This is the
"proper" way to do password-based encryption. This could be slightly
misleading, since irrelevant of the length of the password, the
algorithm itself is only acting on an 8-byte key. Longer passwords
are hashed down to size, so it's possible that there could be more
than one password that successfully decrypts the data. Assuming the
hash function is secure, it is "computationally infeasible" to figure
out what those other passwords are, but they probably exist. This is
always the case when using a password with an algorithm that has a
fixed key size (i.e. almost all of them).

- --
Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/mbBDwxczzJRavJYRAuieAJ4t/IvawT18b6Q/dqblg+gveyewpACeKZiS
hIOQIsym9rIfjmlakT3zIZk=
=EsJ4
-----END PGP SIGNATURE-----


Wow! Thanks for some very good info!

Hal
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Google Mike | last post by:
Of course, one could always use other kinds of encryption/encoding/obfuscation techniques such as XOR complement, but this example provides an extremely secure version using methods like Blowfish,...
4
by: Harold Crump | last post by:
Greetings, I have a requirement of storing some .xml files on a web server. The files will contain financial information like credit card numbers, so I would like to encrypt them. The files...
22
by: Kamilche | last post by:
I've looked at a few alternatives for encryption with Python, and didn't come up anything very speedy. I've written an encryption algorithm in pure Python that can process 22 megs of data a...
4
by: Geoff Caplan | last post by:
Hi folks, I am looking for a practical way of sending encrypted strings back and forth between a Python HTTP client on Windoze and an Apache/PHP server on Linux. I am looking for a simple,...
34
by: Blake T. Garretson | last post by:
I want to save some sensitive data (passwords, PIN numbers, etc.) to disk in a secure manner in one of my programs. What is the easiest/best way to accomplish strong file encryption in Python? ...
6
by: Richard | last post by:
I'm looking to do my own basic encryption. I've been tyring to do a concept such as: I pass this function the string, key and number of rounds I want to do the encryption. because im round...
1
by: joe | last post by:
Hi does anyone know if there is anycode out there to convert a stream such as a network connection from a compression library to an encryption library. or if there is a compresion lib with...
113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
1
by: Vipul Kulshrestha | last post by:
Hello Friends, I need to an encryption of passpword and store it in a file. I am looking for a code in C. I m having a code in C for Blowfish encryption but it takes long values as input . But I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.