Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How secure is javax.crypto.Cipher?

I know enough about cryptology to make life difficult for a novice programmer and get laughed at by security experts. So with that in mind, I ask: how secure is javax.crypto.Cipher? I realise that anything can be cracked by someone with a will and a way, but I still would like to know relative details.

The reason I ask is I would like to store account names and passwords that will be sent through my Cryptor class that will encrpyt them, and would like to know if this will do the job. If any one has any literature that I could read, that would be greatly apprieciated.

Thanks ~Aedon

like image 215
ahodder Avatar asked Aug 08 '11 21:08

ahodder


People also ask

Is javax crypto cipher thread safe?

Cipher is not thread safe. If you use multithreading for performance and don't want to do synchronization, you can use Jasypt (http://www.jasypt.org/general-usage.html) it has pooled encryptors: PooledPBEByteEncryptor, PooledPBEStringEncryptor. If synchronization is ok for you and you use Spring.

What is javax crypto cipher?

The javax. crypto. Cipher class encapsulates a cipher algorithm. A Cipher either encrypts data or decrypts data. The Cipher class encompasses both asymmetric (public key) and symmetric (private key) algorithms.

What does cipher doFinal return?

Returns the length in bytes that an output buffer would need to be in order to hold the result of the next update or doFinal operation, given the input length inputLen (in bytes). Returns the parameters used with this cipher.

What is GCMParameterSpec?

public class GCMParameterSpec extends Object implements AlgorithmParameterSpec. Specifies the set of parameters required by a Cipher using the Galois/Counter Mode (GCM) mode.


2 Answers

Cipher is a generic class to apply an encryption/decryption algorithm. Its security depends on the actual encryption algorithm used (DES, triple-DES, AES, etc.), on the size of its key, and on the block chaining type that you choose.

like image 58
JB Nizet Avatar answered Sep 27 '22 23:09

JB Nizet


If you intend to store passwords securely, then your requirements are quite different from simply "communicating securely/privately". A Cipher on its own is not enough to protect you. You need to use one of these

  • bcrypt
  • scrypt
  • PBKDF2 from PKCS#5

in that circumstance. Here are some arguments and links concerning password security.

The punchline is that "normal" encryption (or hashing, too) is just way too fast to hold off serious attackers. You want to artificially slow down the entire process to make it as hard as possible for somebody systematically attacking your application. A single user won't notice the difference between 1 or 500 milliseconds when entering a password but for an attacker this means that in order to break your scheme it will take them 500 times as long on the average - so if it would have taken roughly 1 month to find a valid password before, now it will take 500 months.

like image 40
emboss Avatar answered Sep 27 '22 21:09

emboss