0

I have some questions about encryption in java as I'm trying to develop a password-manager-like application for my final test in Computer Science in High School (Germany). The password manager uses a server with a REST API to save the passwords in a database to transfer the passwords encrypted to the user where he might save it or just use it.

  1. I have to do an extension for the browser Chrome to insert the passwords, but Chrome forces me to use JavaScript for writing the extension. So should I decrypt the passwords on the server and send them plain text by SSL or should I send the encrypted password and encrypted private key and let the extension decrypt both. But the problem here is that Java and JavaScript Crypto Libraries aren't creating them the same, so I might need to call a java application from the extension.
  2. I'm currently using RSA/ECB/PKCS1Padding as the Algorithm for encrypting text with public and private keys, I know, there is also AES, but I need public/private keys for my application, and therefore I want to ask if this algorithm is secure enough for saving passwords. Note: I'm encrypting the Private Key with PBE.
  3. As I noted, I'm using PBE to encrypt my private key with a password that the user provides for the Password Manager, I'm using PBEWithSHA1ANdDESede therefore, is this also secure enough or is there anything that is better in the Java Standard Library.
  • 2
    I think you might need to learn more about public key crypto. Look at this answer. crypto.stackexchange.com/questions/25899/… The short version is that public key cryptography is only good for encrypting very short messages, like say a key for a symmetric algorithm. As far as where to perform the encryption, think about where the trust exists. Do the users want to trust the servers with all their passwords? Since that's what you're doing when the server end does the encryption. – Steve Sether Jan 20 at 20:00
3

Before I answer your questions, here are a few principles that will make the answers easier to understand.

  1. Keep network usage to a minimum. All transmissions are vulnerabilities. You are using the network to synchronize passwords between devices. All of the other functions should be performed locally on a cached database.
  2. Sensitive data should stay encrypted whenever possible. Whenever data is not being used, leave it encrypted. Even in memory. Plaintext passwords are naked targets. They should only exist for the brief moments when the user needs them.
  3. Hiding secrets is not the only goal of cryptography. There are four goals in cryptography: confidentiality (hiding secrets); authenticity (verifying that people are who they say they are, and things are from where they say they're from); integrity (verifying that data has not been corrupted); and non-repudiation (don't worry about this one for now).

Now to your questions.

1. Question

should I decrypt the passwords on the server and send them plain text by SSL or should I send the encrypted password and encrypted private key and let the extension decrypt both.

The local application should decrypt both. Remember, we are only using the network to synchronize data between devices. Everything else should be done locally.

The user's whole archive of passwords should be cached on their local device. They are stored encrypted by the user's password (and key or whatever). When the user logs into the password manager application, he gives the application his password and/or key. This gives the password manager application the power to decrypt the database and read the user's passwords.

Basically, the answer is that you do need to decrypt the passwords in JavaScript. But you shouldn't be getting them from the server unless your local cache needs an update.

the problem here is that Java and JavaScript Crypto Libraries aren't creating them the same, so I might need to call a java application from the extension.

No, you don't need to call a Java application from JavaScript. The cryptographic standards you're using are completely interoperable. If you aren't able to make them work together, then you're probably making a mistake.

2. Question

I'm currently using RSA/ECB/PKCS1Padding as the Algorithm for encrypting text with public and private keys, I know, there is also AES, but I need public/private keys for my application, and therefore I want to ask if this algorithm is secure enough for saving passwords.

The first thing you need to know about this is that you probably are still using AES encryption. Symmetric encryption is an important part of asymmetric encryption. RSA keys are not capable of encrypting more than a few hundred bytes. Here's the basic procedure.

Encryption

  • Generate symmetric key A
  • Encrypt message M using A
  • Use the public RSA key to encrypt A
  • Send A+M (both encrypted) to the recipient

Decryption

  • Decrypt A using private RSA key.
  • Decrypt M using A

Also, your question about whether RSA is strong enough is impossible to answer. It depends on your teacher's standards.

3. Question

is there anything that is better in the Java Standard Library

Yes. I don't know what is strong enough for your teacher. But Java certainly has stronger options.

SHA1 is the weakest of all the SHAs. The strongest of all the SHAs is SHA3-512. Adding HMAC makes it even stronger. AES is also much stronger than DES. PBE is kind of ambiguous. I usually prefer to specify PBKDF2 if I need something very strong.

  • 1. I believe, Java only uses RSA. I only encrypt the passwords with RSA and then save them in a database, so I think RSA is usable for this. 2. On the second thing, I read only about JavaScript Crypto capabilities that they aren't as strong as something from system languages. (Especially the Random Number Generator). So I consider, as I'm trying to do a Chrome Extension to execute a java local application for encrypting/decrypting. – Nightloewe Jan 21 at 17:47
  • 1
    Crypto.getRandomValues is a CSPRNG for JavaScript that runs in the browser or an extension. Escaping out to an actual Java app is making things way too complicated for no good reason. – Swashbuckler Jan 21 at 18:32
  • @Nightloewe you also don’t really need an RNG for decryption. – William Rosenbloom Jan 21 at 18:34
  • You should listen to @Swashbuckler. IPC from a browser can turn into a nightmare you don't want to deal with. – William Rosenbloom Jan 21 at 19:41
  • @Nightloewe RSA is a very reasonable choice of key type. But you should know Java supports many more types. For example, in my industry ECC keys are always preferred, and Java supports them both through the standard security interface and third party libraries. – William Rosenbloom Jan 21 at 21:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.