- // 'key' should be 32 bytes for AES256, will be null-padded otherwise
- char keyPtr[kCCKeySizeAES256+1]; // room for terminator (unused)
- bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding)
- CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding,
- keyPtr, kCCKeySizeAES256,
- NULL /* initialization vector (optional) */,
- [self bytes], dataLength, /* input */
- buffer, bufferSize, /* output */
- &numBytesEncrypted);
- private static final String AES_SECRET = "PreDefinedKey";
- /**
- * Method for AES encryption
- * @param raw
- * @param plain
- * @return
- * @throws Exception
- */
- private static byte[] encrypt(byte[] raw, byte[] plain) throws Exception {
- SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES/ECB/PKCS7Padding");
- Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding");
- cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
- byte[] encrypted = cipher.doFinal(plain);
- return encrypted;
- }
- /**
- * AES decryption
- * @param encryptMsg
- * @return
- * @throws Exception
- */
- public static String AESDecrypt(String encryptMsg)
- throws Exception {
- byte[] rawKey = getRawKey(AES_SECRET.getBytes());
- //byte[] enc = toByte(encryptMsg);
- byte[] enc = Base64.decode(encryptMsg, 0);
- byte[] result = decrypt(rawKey, enc);
- return new String(result);
- }
- /**
- * Method for AES decryption
- * @param raw
- * @param encrypted
- * @return
- * @throws Exception
- */
- private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
- SecretKeySpec keySpec = new SecretKeySpec(raw, "AES/ECB/PKCS7Padding");
- Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding");
- cipher.init(Cipher.DECRYPT_MODE, keySpec);
- byte[] decrypted = cipher.doFinal(encrypted);
- return decrypted;
- }
- public static byte[] getRawKey(byte[] seed) throws Exception {
- KeyGenerator kgen = KeyGenerator.getInstance("AES");
- SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
- sr.setSeed(seed);
- //Init for 256bit AES key
- kgen.init(256);
- SecretKey secret = kgen.generateKey();
- //Get secret raw key
- byte[] raw = secret.getEncoded();
- return seed;
- }
- // zeros by default
- byte[] rawKey = new byte[32];
- // if you don't specify the encoding you might get weird results
- byte[] keyBytes = AES_SECRET.getBytes("ASCII");
- System.arraycopy(keyBytes, 0, rawKey, 0, keyBytes.length);
- SecretKey key = new SecretKeySpec(rawKey, "AES");
- Cipher cipher = ...
- // rest of your decryption code
Friday, February 7, 2014
DIY Electromagnetic (HERF) Gun Project
This DIYer built his own Microwave HERF (high-energy radio frequency) gun by using parts from an old microwave oven. The electromagnetic gun works just like a normal microwave with a high energy source triggering a magnetron which produces microwave radiation at 2.45GHz. The targeting part is a waveguide made out of metal which directs the microwaves in one direction instead of letting them scatter.
This DIYer built his own Microwave HERF (high-energy radio frequency) gun by using parts from an old microwave oven. The electromagnetic gun works just like a normal microwave with a high energy source triggering a magnetron which produces microwave radiation at 2.45GHz. The targeting part is a waveguide made out of metal which directs the microwaves in one direction instead of letting them scatter.
Subscribe to:
Posts (Atom)