Java 256-bit AES Password-Based Encryption

Share the password (a char[]) and salt (a byte[]—8 bytes selected by a SecureRandom makes a good salt—which doesn’t need to be kept secret) with the recipient out-of-band. Then to derive a good key from this information: /* Derive the key, given password and salt. */ SecretKeyFactory factory = SecretKeyFactory.getInstance(“PBKDF2WithHmacSHA256”); KeySpec spec = new PBEKeySpec(password, … Read more

Encrypt and decrypt a string in C#? [closed]

EDIT 2013-Oct: Although I’ve edited this answer over time to address shortcomings, please see jbtule’s answer for a more robust, informed solution. https://stackoverflow.com/a/10366194/188474 Original Answer: Here’s a working example derived from the “RijndaelManaged Class” documentation and the MCTS Training Kit. EDIT 2012-April: This answer was edited to pre-pend the IV per jbtule’s suggestion and as … Read more

How to convert a letter to an another letter in Java [duplicate]

You could use something like the following algorithm to accomplish this: // Our input string. String input = “I love fish”; // Contains the “encrypted” output string. StringBuilder encrypted = new StringBuilder(); // Process each character in the input string. for (char c : input.toCharArray()) { if (Character.toLowerCase(c) != ‘a’ && Character.isLetter(c)) { // If … Read more

python building coder for ceasar cipher

You don’t have to use dictionaries… There is an easier way, using string module: from string import printable, maketrans def caesar(string, key): shifted_alphabet = printable[key:] + printable[:key] table = maketrans(printable, shifted_alphabet) return string.translate(table) string = raw_input(“Enter something> “) #input for python 3 while 1: try: key = int(raw_input(“Enter key (0-25): “)) except: print “Key should … Read more

Encrypt a Library Linux

Python has to read the library to run it, and to read it correctly, it must be decrypted. Otherwise how do you expect python to be able to run encrypted code? If you distribute an encrypted library, you have to add code to decrypt the library first before importing it. Otherwise there is no way … Read more