Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symmetric-key encryption algorithm

I'm looking for a secure symmetric-key encryption algorithm compatible with both JavaScript and Java.

I've tried implementing one but I had some encoding issues.

like image 858
Diogo Cardoso Avatar asked Dec 18 '11 16:12

Diogo Cardoso


3 Answers

This page has CTR mode, which is available in Java. I would recommend keys of 128 bits or you might run into trouble regarding the Java export policies on larger key sizes.

Here is a page which uses some very usefull methods of encryption, including password encryption techniques and ciphres with integrity checks and authentication, although you may need the bouncy castle libraries on Java to match those all.

There are oodles of libraries for JavaScript, but character encoding issues will be present on any of them. So make sure you use the same encoding both on the JavaScript side as well as on the Java side. A quick look up assures me that JavaScript uses UTF-16 internally, but don't hang me up on that.

Finally, don't try this at home, the libraries are there, use them (especially if they mention tests and/or official test vectors).

like image 24
Maarten Bodewes Avatar answered Oct 04 '22 10:10

Maarten Bodewes


You don't want to encrypt with JavaScript, especially on the client-side where it is open to tampering, and has no cryptographically secure random number generator.

I've tried implementing one but I had some encoding issues.

You tried to write your own encryption algo? You've gone against everything that the security world hold dear. No. Actual tutorials that explain how encryption works are so scared that people are going to screw things up because they don't understand the math behind it, I've actually seen this in one of them:

enter image description here

If you don't understand encryption, things like, what "cryptographically secure pseudo random number generator" actually is, and common attacks on it, you shouldn't do that.

If you don't understand things like side-channel attacks, you shouldn't do it.

If you don't understand what's going on in crypto and have read at-least two books on it you have no business implementing it.

Crypto is not a magic black box, it's something that is very VERY easy to screw up, even without touching any bit of code in a packaged solution.

What should you do? Forget about JS encryption. I know, I've tried it myself. It's a waste of time. Learn from my mistakes.

Go get an SSL certificate, SSL is the best way for us to encrypt messages on the transport level from a server to a client. It's about as secure as you can get. If you face an advesary that can defeat SSL, trust me, your JS-based crypto is also compromised.

Once it's at the server where it's secure from being tampered with, encrypt it. Anything else is a really long way to waste your time.

Also, go read these books:

![This one is free][4] [![This one is cash money][5]][5] (source: [schneier.com](https://www.schneier.com/images/book-ce-150w.jpg))

Then when you understand them come back and scream at me about why I'm wrong and don't understand how much you need JS on the client to do crypto.

like image 140
Incognito Avatar answered Oct 04 '22 08:10

Incognito


There is an excellent DES (and by extension 3DES) implementation in JS, which I use quite often. I'll put up the link Monday, when I'm at the office and have it ready. Results from this (after base64 encoding for the transport) work perfectly with .Net/Mono (builtin), Java (bulitin) and PHP (mcrypt).

Found the links, but both are dead: http://www.shopable.co.uk/des.html and http://www.netdealing.com. I have put it up on http://pastebin.com/KbRsWKJY

like image 33
Eugen Rieck Avatar answered Oct 04 '22 09:10

Eugen Rieck