sentence
stringlengths 1
1.38k
| label
stringclasses 3
values |
---|---|
I had been working 5-6 years to get one running.
|
p
|
Much practical advice from decades of doing actual infosec.
|
o
|
128 bit data encryption using Java.
|
o
|
I need to store some sensitive data by encrypting it with atleast 128 bit key.
|
o
|
I investigated into javax.crypto package and found that there are certain Cipher names, like PBEWithMD5AndDES or PBEWithSHA1AndDESede which provides encryption upto 56 bit and 80 bit ( URL_http://en.wikipedia.org/wiki/DESede [ URL_http://en.wikipedia.org/wiki/DESede ] ).
|
o
|
I referred other guys posts but those are mainly using RSA and in my understanding RSA is generally suitable for encrypting the communication data (with private-public key pair).
|
o
|
My need is different, I just want to store the data and retrieve it back by decrypting it.
|
o
|
Therefore I don't need any private-public key pairs.
|
o
|
Please let me know if you have any idea about this.
|
o
|
Thanks in advance.
|
o
|
Use URL_http://en.wikipedia.org/wiki/Advanced_Encryption_Standard [Advanced- Encryption-Standard] (AES).
|
o
|
It supports Key lengths of 128, 192, or 256 bits.
|
o
|
The URL_http://www.hoozi.com/Articles/AESEncryption.htm [algorithm] is simple.
|
p
|
The Sun Java website has a URL_http://java.sun.com/developer/technicalArticles/Security/AES/AES_v1.html [section-explaining-how-to-do-AES] encryption in Java.
|
o
|
From Wikipedia...
... the Advanced Encryption Standard (AES), also known as Rijndael, is a block cipher adopted as an encryption standard by the U.S. government.
|
p
|
It has been analyzed extensively and is now used worldwide, as was the case with its predecessor, the Data Encryption Standard (DES)...
|
p
|
So as a rule of thumb you are not supposed to use DES or its variants because it is being phased out.
|
o
|
As of now, it is better to use AES.
|
o
|
There are other options like URL_http://en.wikipedia.org/wiki/Twofish [Twofish] , URL_http://en.wikipedia.org/wiki/Blowfish_(cipher) [Blowfish] etc also.
|
o
|
Note that Twofish can be considered as an advanced version of Blowfish.
|
o
|
I have had good success in the past with URL_http://www.bouncycastle.org/ [ URL_http://www.bouncycastle.org/ ] (they have a C# version as well).
|
p
|
You need to download and install the unlimited strength JCE policy file for your JDK.
|
o
|
For JDK 6, it is on URL_http://java.sun.com/javase/downloads/index.jsp [ URL_http://java.sun.com/javase/downloads/index.jsp ] at the very bottom.
|
o
|
Isn't it required only for AES-192 or 256?
|
o
|
I believe AES-128 doesn't require the unlimited strength JCE policy files.
|
o
|
Combining 3 different replies gives what I think is the correct answer.
|
p
|
Download encryption libraries from URL_http://www.bouncycastle.org/java.html [Bouncycastle] then you need to download the "Unlimited Strength Jurisdiction Policy" from URL_http://www.oracle.com/technetwork/java/javase/downloads/index.html [Oracle] (the files are at the bottom of the download page).
|
o
|
Make sure you read the Readme-file on how to install it.
|
o
|
Once you have done this, and using the sample code supplied with the Bountycastle package you should be able to encrypt your data.
|
o
|
You can go with a tripple DES implementation, which will give you 112 bits key (often referred to as 128 bit, but only 112 of them are actually secure), or as previously stated, you can use AES.
|
p
|
My money would be on AES.
|
o
|
Heads Up: It's BounCycastle, not BounTycastle.
|
o
|
I'm not a crypto expert by any means (so take this suggestion with a grain of salt), but I have used URL_http://en.wikipedia.org/wiki/Blowfish_(cipher) [Blowfish] before, and I think you can use it for what you need.
|
o
|
There is also a newer algorithm by the same guy called URL_http://en.wikipedia.org/wiki/Twofish [Twofish] .
|
o
|
Here is a URL_http://www.hotpixel.net/software.html [website-with-a-Java- implementation] , but be careful of the license (it says free for non- commercial use).
|
p
|
You can find that link also from URL_http://www.schneier.com /blowfish-download.html [Bruce-Schneier's-website] (the creator of both algorithms).
|
o
|
the link in "website with java implementation" is dead.
|
o
|
plz update it...
|
o
|
Thanks Michael, after trying out many things in JCE, I finally settled for bouncycastle.
|
o
|
JCE supports AES for encryption and PBE for password based encryption but it does not support combination of both.
|
o
|
I wanted the same thing and that I found in bouncycastle.
|
o
|
The example is at : URL_http://forums.sun.com/thread.jspa?messageID=4164916 [ URL_http://forums.sun.com/thread.jspa?messageID=4164916 ] .
|
o
|
Is Bouncy Castle API Thread Safe?
|
o
|
Is URL_http://bouncycastle.org/java.html [Bouncy-Castle-API] Thread Safe ?
|
o
|
Especially, CODESNIPPET_JAVA1 .
|
o
|
I am planning to write a singleton Spring bean for basic level cryptography support in my app.
|
o
|
Since it is a web application, there are greater chances of multiple threads accessing this component at a time.
|
p
|
So tread safety is essential here.
|
o
|
Please let me know if you have come across such situations using Bouncy Castle.
|
o
|
Thanks in advance.
|
o
|
It really does not matter if the API/Code is thread safe.
|
p
|
CBC encryption in itself is not thread safe.
|
n
|
Some terminology - CODESNIPPET_JAVA1 .
|
o
|
A really simple CBC implementation can look like:P1, P2, P3
Plain text messages CODESNIPPET_JAVA2 .
|
p
|
As you can see, the result of encrypting P1, P2 and P3 (in that order) is different from encrypting P2, P1 and P3 (in that order).
|
o
|
So, in a CBC implementation, order is important.
|
o
|
Any algorithm where order is important can not, by definition, be thread safe.
|
p
|
You can make a Singleton factory that delivers encryption objects, but you cant trust them to be thread safe.
|
p
|
Yes, Tnilsson, your reasoning is right.
|
o
|
I found the following post, URL_http://www.bouncycastle.org/devmailarchive/msg04715.html from bouncy castle's mailing list.
|
o
|
It's not completely thread safe (atleast AES engine).
|
p
|
The J2ME version is not thread safe.
|
n
|
Java 256-bit AES Password-Based Encryption.
|
o
|
I need to implement 256 bit AES encryption, but all the examples I have found online use a "KeyGenerator" to generate a 256 bit key, but I would like to use my own passkey.
|
o
|
How can I create my own key?
|
o
|
I have tried padding it out to 256 bits, but then I get an error saying that the key is too long.
|
n
|
I do have the unlimited jurisdiction patch installed, so thats not the problem :) Ie.
|
o
|
The KeyGenerator looks like this ... CODESNIPPET_JAVA1 .
|
o
|
URL_http://java.sun.com/developer/technicalArticles/Security/AES/AES%5Fv1.html [Code-taken-from-here]
I was actually padding the password out to 256 bytes, not bits, which is too long.
|
n
|
The following is some code I am using now that I have some more experience with this.
|
o
|
CODESNIPPET_JAVA2 .
|
o
|
The "TODO" bits you need to do yourself :-) .
|
o
|
Could you clarify: does calling kgen.init(256) work?
|
o
|
Yes, but this automatically generates a key ... but since I want to encrypt data between two places, I need to know the key beforehand, so I need to specify one instead of "generate" one.
|
o
|
I can specify a 16bit one which works for 128bit encryption which works.
|
p
|
I have tried a 32bit one for 256bit encryption, but it did not work as expected.
|
o
|
If I understand correctly, you are trying to use a pre-arranged, 256-bit key, specified, for example, as an array of bytes.
|
p
|
If so, DarkSquid's approach using SecretKeySpec should work.
|
o
|
It's also possible to derive an AES key from a password; if that's what you are after, please let me know, and I'll show you the correct way to to do it; simply hashing a password isn't the best practice.
|
p
|
Be careful about padding a number, you may be making your AES less secure.
|
p
|
@erickson: that is exatly what i need to do (derive an AES key from a password).
|
o
|
@Nippysaurus: Any luck?
|
o
|
Please comment on my answer if you still have problems it doesn't address.
|
o
|
@erickson: Nope.
|
o
|
I got both .NET and Java to compile something in what I thought was 256bit, but the results were different.
|
o
|
I might not need to do the Java side after all.
|
o
|
As a last resort we will probably use bouncycastle :).
|
o
|
@Nippysaurus Were you able to get this to work?
|
o
|
If so, would you mind posting the complete solution including the code from AES_v1.html?
|
o
|
Sorry this was more than two years ago and I havent done any Java since.
|
n
|
Share the CODETERM1 (a CODETERM2 ) and CODETERM3 (a CODETERM4 8 bytes selected by a CODETERM5 makes a good saltwhich doesn't need to be kept secret) with the recipient out-of-band.
|
p
|
Then to derive a good key from this information (in Java 6): CODESNIPPET_JAVA1 .
|
p
|
Now send the CODETERM6 and the CODETERM7 to the recipient.
|
o
|
The recipient generates a CODETERM8 in exactly the same way, using the same salt and password.
|
o
|
Then initialize the cipher with the key _and_ the initialization vector.
|
o
|
CODESNIPPET_JAVA2 .
|
o
|
A CODETERM9 with the message "Illegal key size or default parameters" means that the cryptography strength _is_ limited; the unlimited strength jurisdiction policy files are not in the correct location.
|
n
|
In a JDK, they should be placed under CODETERM10 Based on the problem description, it sounds like the policy files are not correctly installed.
|
p
|
Systems can easily have multiple Java runtimes; double- check to make sure that the correct location is being used.
|
p
|
Argh.
|
o
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.