Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing encryption algorithm

Tags:

java

md5

aes

Does anyone know good tutorials to change PBEWithMD5AndDES encryption algorithm to AES for a Java application? Specially , I want to know what precautions I should take while changing this algorithm to more secure one. Any important test cases to check before and after algorithm changes. Another question is since I have used PBEWithMD5AndDES , most of the user passwords are encrypted using that algorithm. So if I change my algorithm to AES , how do I make sure that decryption of passwords happen with old algorithm while I can still use new algorithm for any new encryption.

like image 952
yogsma Avatar asked Mar 09 '11 17:03

yogsma


People also ask

What are the three 3 different encryption methods?

The three major encryption types are DES, AES, and RSA.

Can you reverse encryption?

Encryption can always be reversed. The point of encryption is to take a message and encode it with a secret key so that only another person who has the key can reverse the encryption and read the message.

Are there any unbreakable encryption algorithms?

There is only one known unbreakable cryptographic system, the one-time pad, which is not generally possible to use because of the difficulties involved in exchanging one-time pads without their being compromised. So any encryption algorithm can be compared to the perfect algorithm, the one-time pad.


3 Answers

Normally you wouldn't encrypt a users password, you'd just hash it with a salt instead.

Migrating from one encryption system to another is going to be a bit of a pain, as I see it you have two options:

  1. During the upgrade process decrypt then re-encrypt all the passwords
  2. Add a flag indicating the encryption method used. All existing passwords will obviously be set to the current standard. New users will be set to whatever method you choose and you can migrate other users when they change their password.
like image 118
brain Avatar answered Sep 28 '22 23:09

brain


If you've already got data encrypted in format a, and you want to start using another encryption scheme, b, I can think of two ways to accomplish this:

  1. Decrypt all of your data and re-encrypt it using `b`. This approach would be good when you can take your data store offline and "fix everything at once."
  2. For each item you attempt to decrypt, try to decrypt it using `b` first. If that fails, decrypt it using `a`. The next time you try to encrypt something, make sure you use `b`. This approach could be used when you can't take your data store offline, but you want to encrypt all of your data using another algorithm. All of your data will eventually be encrypted using the other algorithm.
like image 31
David Weiser Avatar answered Sep 29 '22 00:09

David Weiser


There's really no problem changing algorithms. What you need to do is decrypt the cipher text and then encrypt the resulting plain text with the new algorithm. That's straightforward. If you are going to perform this transition over time, I would suggest creating a new database table that keeps track of whether a particular entity (based on unique id) has been transfered to the new algorithm. If it has, then you simply use the new algorithm to decrypt it and you can forget about it, if not, then you use the old algorithm to decrypt it. Regardless though, all new encryption should be performed with the new algorithm.

Now, there's a second issue here. Why are you bothering to decrypt passwords? Just save the hash of the password and forget about it. If you are able to decrypt passwords, you introduce a potential vulnerability. If a malicious user can get a hold of your key you use to encrypt those passwords, then they could access the plain text of the password. Not only could the user then use that information to compromise your system, if your users use the same username/password combination for other sites, those accounts would be compromised as well. You should only store a hash of the password (SHA is a good one, don't use MD5) and then when the user attempts to log in, you hash the input and compare the two results. You have no need to know what the plain text password is.

like image 29
Chris Thompson Avatar answered Sep 29 '22 00:09

Chris Thompson