Algorithms
There are a few dozen standard algorithms. The ones we’re most likely to be interested in are:Symmetric Cipher
- KeyGenerator – creates symmetric key
- SecretKeyFactor – converts between symmetric keys and raw bytes
- Cipher – encryption cipher
- AlgorithmParameters – algorithm parameters
- AlgorithmParameterGernerator – algorithm parameters
Asymmetric Cipher
- KeyPairGenerator – creates public/private keys
- KeyFactor – converts between keypairs and raw bytes
- Cipher – encryption cipher
- Signature – digital signatures
- AlgorithmParameters – algorithm parameters
- AlgorithmParameterGernerator – algorithm parameters
Digests
- MessageDigest – digest (MD5, SHA1, etc.)
- Mac – HMAC. Like a message digest but requires an encryption key as well so it can’t be forged by attacker
Certificates and KeyStores
- KeyStore – JKS, PKCS, etc.
- CertStore – like keystore but only stores certs.
- CertificateFactory – converts between digital certificates and raw bytes.
- Use a variant of AES. Only use AES-ECB if you know with absolute certainty that you will never encrypt more than one blocksize (16 bytes) of data.
- Always use a good random IV even if you’re using AES-CBC. Do not use the same IV or an easily predicted one.
- Do not use less than 2048 bits in an asymmetric key.
- Use SHA-256 or better. MD-5 is considered broken, SHA-1 will be considered broken in the near future.
- Use PBKDF2WithHmacSHA1 to create AES key from passwords/passphrases. (See also Creating Password-Based Encryption Keys.)
In practice many if not most people use a third-party cryptographic library like BouncyCastle.
Final Notes
- Storing the text password with hashing is most dangerous thing for application security today.
- MD5 provides basic hashing for generating secure password hash. Adding salt make it further stronger.
- MD5 generates 128 bit hash. To make ti more secure, use SHA algorithm which generate hashes from 160-bit to 512-bit long. 512-bit is strongest.
- Even SHA hashed secure passwords are able to be cracked with today’s fast hardwares. To beat that, you will need algorithms which can make the brute force attacks slower and minimize the impact. Such algorithms are PBKDF2, BCrypt and SCrypt.
- Please take a well considered thought before applying appropriate security algorithm.
- Generate Secure Password Hash : MD5, SHA, PBKDF2, BCrypt Examples
- How to Encrypt user passwords
- Symmetric and Asymmetic encrption overview
- Symmetric-vs-Asymmetric-Encryption
No comments:
Post a Comment