List News Background articles Commentaries Development/Java IT Security Computer Guides & Tips

Password-based Encryption made easy

Added at 09/28/2015 by Frank Hissen

Here is a simple example for using strong password-based encryption for non-cryptographers with CrococryptLib.

Uses the following defaults: PBKDF2 key derivation with a SHA512 HMAC, 100000 iterations, 512 Bit salt and AES-256 in CBC mode.

public class SimplePBEEncryptionExample { public static void main(String[] args) throws Exception{ String password = "Demo Password!"; String textToencrypt = "Secret text to be encrypted, could also be any binary data"; CompactPasswordKey key = CompactPasswordKey.generateKey(new Secret(password)); String encryptedMessage = new CompactEncryption(key).encryptToBase64(new StringData(textToencrypt)); System.out.println("\nEncrypted message: " + encryptedMessage); System.out.println("\nDecrypted message: " + new CompactEncryption(key).decryptFromBase64(encryptedMessage)); } }

Creates this output:

Encrypted message: AAAAAAIAAAAQ1SHBVLPfXMbOOV7rvSnrcgAAAGBwEOiB9h3H-KtVW1-1XPFi7H2dm61_0-DWaiCUafgzFuUaelB46X1pmijNCWd92BkqLlJ0F2NLbzFFGYvJGJgVztFf49WnAJ_J8B0OXLWgYuLkPdygH57CAHTnhSN9pP8 Decrypted message: Secret text to be encrypted, could also be any binary data

For more information go to the CrococryptLib Homepage.


HissenIT is a small business in Germany focusing on IT security software development and consulting. Owner and computer scientist Frank Hissen has over 19 years experience in various positions as security expert in IT projects. He mainly worked for large businesses but also medium-sized companies. Mr. Hissen is specialized in encryption and other cryptographic technologies.

Categories: IT Security Development/Java


Post your comment


If you like this page, it would be a great thing if you share it with others:

Mail Facebook Twitter Pinterest LinkedIn
reddit Digg StumbleUpon XING
WhatsApp Telegram