Java + PHP Encryption Algorithm Implementation - java

I'm using this site for my salted hashing.
I've got a Java application with the Java implementation of the PBKDF2 encryption system from the above link running fine it generates the hashes and decodes them using the PBKDF2WithHmacSHA1 algorithm. I'm trying to duplicate the registration process in PHP using the same algorithm but I can't get it working.
Reference For Java Algorithm Names
Can someone who understands security more help me change the PHP implementation on the link above so it would work with the PBKDF2WithHmacSHA1 algorithm in the Java version?
(If you want me to post source code I can but it's virtually the same as in the link)
What i've tried so far:
Changing the hash algorithm in the PHP version to PBKDF2WithHmacSHA1 but it throws a PBKDF2 ERROR: Invalid hash algorithm.
Changing the Java algorithm to SHA256 but the Java code doesn't seem to match up with the PHP code in any way so it just errors.
Looking here for the right algorithm, but not finding it.
The overall goal is to let the user register on the website and log into the desktop app. Any pointers would be much appreciated (I would love to provide more details but i'm still learning the security side of things so if you spot any big problems with what i'm trying to do can you explain!)

Try this from the php documentation
http://www.php.net/manual/en/function.hash-hmac.php
Here is an efficient PBDKF2 implementation:( 2nd or 3rd down )

Related

Encryption & Decryption for Mobile Webservice

I'm working on a mobile App which is to be build in Android (Native) , iOS (Native) & PhoneGap. For security I'm already using SSL, but as per client requirement another encryption is to be implemented in all webservices( Mobile end and Server) . But I'm unable to implement encryption which works well in Java, Objective-C and JavaScript.
I could manage to get AES-256 working in all the platforms , but it works very slow in Android. Library used for the same was RNCryptor.
Can you please suggest me any Encryption/Decryption library which is compatible along at least Java & Objective-C.
AES-256 a correct choice and should not be a performance problem. Most cpu chips include special instructions to allow faster implementations, Apple ARM chips do as do may Intel chips. If you are going to claim that encryption is slow for an implementation you need to supply test times for all platforms, generate them and post them.
Obtaining the same results from encryption, AES-256 in this case, is simply supplying the exact same inputs with the exact required lengths and exact same options--that is all.
Providing secure encryption is more than just a key, data and an AES-256 library. There needs to be an iv, if the key is week it needs to be extended, passwords are generally extended with PBKDF2 or it's like. These require more information to be added to the encrypted data that is passed. There is also data padding such as PKCS#7. RNCryptor handles all this but for interoperability requires the other-end to use the same scheme. Then there is the issue of securing the encryption key and exchanging it with the other-side.

PBKDF2WithHmacSHA512 in Java

Till now I have used "PBKDF2WithHmacSHA1" for encrypting passwords. However, I recently thought that it would be better to upgrade to "PBKDF2WithHmacSHA512" since it is considered a stronger algorithm.
However, Java does not support "PBKDF2WithHmacSHA512" out of the box. I tried Googling but could come up with no definite solution.
Could you please tell me how can I encrypt passwords using "PBKDF2WithHmacSHA512" in Java. It would be really helpful if you could provide code since I have limited idea about this.

How to compare passwords in Java hashed by devise gem ruby on rails

I am working on a task of authenticating users from mysql db. The user passwords are hashed by devise gem framework for Ruby on Rails.
Docs says it is also using BCrypt to hash the passwords. The problem with jBcrypt is that
BCrypt.checkpw("Google123", "$2a$10$Qj.7VHa8tJcSFAU9eR1o8eCiXzFSkQPQxpODL971xKiDFbYjdaWyS"); // not working nor
BCrypt.checkpw("test123test", "$2a$10$vGeVVu.E0XGjlNEa0xMCK.R0SEH0aFuyJpefrq01Axz6WSbHApPEu"); // is working. It always returns false.
Although it should return true since Google123 hashing is
$2a$10$Qj.7VHa8tJcSFAU9eR1o8eCiXzFSkQPQxpODL971xKiDFbYjdaWyS
using BCrypt algorithm.
Can you please help me fix this issue or should I look for some other Implementation of Bcrypt.
This should be working just fine. Take a look at the documentation here http://static.springsource.org/spring-security/site/docs/3.1.x/apidocs/org/springframework/security/crypto/bcrypt/BCrypt.html.

Which encryption algorithm is useful for encrypting a file stored on disk?

I have some text that is in a file. I want to encrypt this file so that an end user can not read or write to this file, but the application can read it. There can be a stored secret in the application because it is being secured in another way.
What type of Encryption support these requirements?
I was thinking of AES. I do not know much about encryption, and was looking for a starting point. An algorithm or a framework suggestion would be great.
One last note, the code is in Java running on a Windows and Linux environment.
Since you've tagged the post as "Java" - I'd recommend looking at the "Java Cryptography Extension" (JCE). Since J2SE 1.4 it's been bundled with the SDK and JRE.
And of course, a requisite example and overview of using AES in the JCE.
If the application can read it, the application has a key in it. And if the application has a key in it, a sufficiently energetic user can find that key and use it for themselves. Or spy on memory and see the decrypted version.
AES or RSA would be just fine. An important thing to notice though is that once your program decrypts data, a reverse engineer would easily recover the plaintext without any knowledge of the key or algorithm of encryption.

Encryption of IP address

I need to encrypt an IP address, save it to file, and then be able to retrieve it later. I was wondering if anyone could suggest a good way to do this. Just the name of some encryption algorithms would be fine or links to resources.
Ive done my research and have come up with a few solutions. Just wanted to make sure there wasnt something I missed. If it helps at all, the application is written in java. We do use JNI for some native functions, but would prefer to stay away from JNI.
Thanks
EDIT:
Its a client/server model. The server will send the encrypted ip address to the client. The client will decrypt it, and then connect to that address.The data will be just a string. Its IPv4.
As other answers have already indicated, AES is your best bet for this problem. However, as is always the case with encryption, the real problem is not which algorithm to choose; it is how to keep your key a secret. If it is simply a string in your source code, it would take very little work for someone to figure that key out and use it to decrypt your file.
Assuming that you want arbitrary encryption on the client then you have a serious key management problem. It is pretty trivial to reverse engineer client code to obtain an embedded encryption key. And you need to consider what you'd do if that key is compromised and splattered all over the internet. Once it's embedded in your code then it's out of your hands (see CSS and deCSS for more fun reading on that subject).
So, a better solution is to have the server do the encryption and decryption and the client to just send up a bunch of bytes that it's stored locally.
Now, what's a good way of encrypting stuff on the server in an easy to maintain manner? I'm talking about key management; ease of use; strength of encryption; easy Ant/Maven targets/goals to manage the generation of said server side keys and so on. One framework that works really well for me is KeyCzar by Google. Simple API and external management is a piece of cake. Take a look.
I can answer to your straight question about encryption algorithm: AES
Java has classes for that!
But I still have my doubts about the robustness of you solution
I'd personally use AES.
Some more resources:
http://java.sun.com/developer/technicalArticles/Security/AES/AES_v1.html
Java 256-bit AES Password-Based Encryption
http://www.aescrypt.com/java_aes_crypt.html
I strongly recommend using the BouncyCastle library for Java. It's a lot cleaner than the built-in crypto stuff in Java and significantly easier to understand. Instead of mucking around with passing names of algorithms to methods and seeing if you actually get a cipher back you can just use new. Much easier.
You mentioned you have a few solutions, why not mention them.
Also, this is a very general question, are you looking for a symmetric algorithm or prefer public/private key, or something that uses both?
If you are looking at keeping the key on the server, since IP addresses are small (is this for IPv6, http://en.wikipedia.org/wiki/IPv6) then RSA would be a good choice, as you can then keep the public key on the server but no one can create a new key without the private key.
How will you be using the data? If you are going to decrypt all of them then just keep them in one file, zip it, then encrypt the entire file.
More details would help to narrow this down, as there are a large number of solutions.
But for libraries, in Java, I like BouncyCastle (http://bouncycastle.org/) as they give a large selection and works well if you need to exchange keys with .NET.
UPDATE:
Based on the latest update to the question the biggest concern is how to exchange the encryption key.
Since this is being sent to a client, your best bet may be to use something like RSA to help with this. The client would have a private key, and the server would have the public key of each client, so that if one is compromised the entire system isn't. Then, the server generates a symmetric key (AES is fine, I like IDEA), and encrypts that key. Then, you transmit both pieces to the client, the client then decrypts the symmetric key and then the IP address.
This idea was made popular by PGP.
You may want to use BouncyCastle, as I mentioned, so that if your client is written in .NET or Java you can still do the key exchange, since it has APIs for both platforms.
How you get the key to the server, from the client, or vice versa, depends on many factors, but that will be the weak link in this whole system, and so that part needs to be designed carefully.
As commented elsewhere, it is pointless. The information is available by other means so encrypting it via this channel is a compete waste of time. Netstat is yet another way the address can be detected.
Is there no way to route the TCP traffic through a proxy IP and "obfuscate" the IP that way?
I don't see the issue there unless the said provider of the proxy blocks the required ports according to projects needs. It's too bad Cloudflare wont allow anything except HTTP/S requests through their service unless you get on Enterprise, otherwise there is your solution in a blink.

Categories