473,811 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(s CryptoKey.getBy tes("UTF8"),
"Blowfish") ;
IvParameterSpec oIV = new IvParameterSpec (sCryptoVector. getBytes("UTF8" ));
Cipher oCipher = Cipher.getInsta nce("Blowfish/CBC/PKCS5Padding");
oCipher.init(Ci pher.DECRYPT_MO DE, 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 10172
-----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(s CryptoKey.getBy tes("UTF8"),
"Blowfish") ;
IvParameterSpec oIV = new
IvParameterSpec (sCryptoVector. getBytes("UTF8" )); Cipher
oCipher = Cipher.getInsta nce("Blowfish/CBC/PKCS5Padding");
oCipher.init(Ci pher.DECRYPT_MO DE, 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.sp ec.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 "computationall y 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/mbBDwxczzJRavJY RAuieAJ4t/IvawT18b6Q/dqblg+gveyewpAC eKZiS
hIOQIsym9rIfjml akT3zIZk=
=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(s CryptoKey.getBy tes("UTF8"),
"Blowfish") ;
IvParameterSpec oIV = new
IvParameterSpec (sCryptoVector. getBytes("UTF8" )); Cipher
oCipher = Cipher.getInsta nce("Blowfish/CBC/PKCS5Padding");
oCipher.init(Ci pher.DECRYPT_MO DE, 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.sp ec.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 "computationall y 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/mbBDwxczzJRavJY RAuieAJ4t/IvawT18b6Q/dqblg+gveyewpAC eKZiS
hIOQIsym9rIfjml akT3zIZk=
=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
3279
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, MD5, DES, etc. This took me about 4 hours to figure out and perfect, but the two functions below will work with PHP on many versions of Linux. I have RedHat 9, in this case. I designed this to use a pretty small compression and encryption...
4
3449
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 will stay there until another program downloads them and deletes the files. My question is - which of the functions in the mcrypt library provide
22
3246
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 second. I know it's not secure, but it should be enough to ward off casual hacking. Does someone know of something speedier? --Kamilche
4
3003
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, lightweight symmetrical solution using, say, blowfish: SSL would be a last resort as I suspect it will cause fairly major installation issues on the client. Encryption in PHP uses a wrapper around the mcrypt C library.
34
4134
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? Any modern block cipher will do: AES, Blowfish, etc. I'm not looking for public key stuff; I just want to provide a pass-phrase. I found a few modules out there, but they seem to be all but abandoned. Most seem to have died several years ago. ...
6
12995
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 shifting the bits the decryption doesn't work.. :P Am I going about this all wrong or does anybody know an easier way (besides getting an open source algo class such as Crypto++) I'm super new to fooling with the bits/encryption
1
1514
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 encryption. I am trying to compile vnc and replace the zlib compression with blowfish encryption. i dont see why i cant be done but i cant figure out a way to write a function that will replace zlib encryption with blowfish compression. i am looking at 2...
113
12362
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 algorithm work with strings that may or may not be unicode 3) Number of bytes back must either be <= number of _TCHARs in * sizeof(_TCHAR), or the relation between output size and input size can be calculated simply. Has to take into account the...
1
8259
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 want to pass a String value as input. as password can in string or number . Please let me know site where i can get the Code or algo. for the Blowfish which can convert stirng values.
0
10648
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10389
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10402
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10135
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9205
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7670
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3867
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3018
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.