Processing and AES.
in
Programming Questions
•
1 year ago
http://java.sun.com/developer/technicalArticles/Security/AES/AES_v1.html
I'm trying to implement this code.
This is the sketch:
- import java.security.*;
- import javax.crypto.*;
- import javax.crypto.spec.*;
- import java.io.*;
- void setup() {
- String message="This is just an example";
- // Get the KeyGenerator
- KeyGenerator kgen = KeyGenerator.getInstance("AES");
- kgen.init(128); // 192 and 256 bits may not be available
- // Generate the secret key specs.
- SecretKey skey = kgen.generateKey();
- byte[] raw = skey.getEncoded();
- SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
- // Instantiate the cipher
- Cipher cipher = Cipher.getInstance("AES");
- cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
- byte[] encrypted =
- cipher.doFinal((args.length == 0 ?
- "This is just an example" : args[0]).getBytes());
- println("encrypted string: " + encrypted);
- cipher.init(Cipher.DECRYPT_MODE, skeySpec);
- byte[] original =
- cipher.doFinal(encrypted);
- String originalString = new String(original);
- println("Original string: " +
- originalString + " " + original);
- }
- void draw() {
- }
At line 14..NoSuchAlgorithmException
Mmm..Why?..It has to be included in standard Java.
1