This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.security.SecureRandom; | |
public static byte[] genIV(int len) throws Exception{ | |
byte[] arr = new byte[len]; | |
SecureRandom prng = SecureRandom.getInstance("SHA1PRNG"); | |
prng.nextBytes(arr); | |
return arr; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int decrypt( | |
void* buffer, | |
int buffer_len, | |
char* IV, | |
char* key, | |
int key_len | |
){ | |
MCRYPT td = mcrypt_module_open("rijndael-128", NULL, "cbc", NULL); | |
int blocksize = mcrypt_enc_get_block_size(td); | |
if( buffer_len % blocksize != 0 ){return 1;} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String decrypt(byte[] cipherText, String encryptionKey) throws Exception{ | |
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding", "SunJCE"); | |
SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES"); | |
cipher.init(Cipher.DECRYPT_MODE, key,new IvParameterSpec(IV.getBytes("UTF-8"))); | |
return new String(cipher.doFinal(cipherText),"UTF-8"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void* padBuffer(void* buf, int buflen, int blocklen){ | |
void* barr; | |
int barrlen; | |
if(buflen > blocklen){ | |
barrlen = buflen + (blocklen-(buflen%blocklen)); | |
}else{ | |
barrlen = blocklen; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static byte[] padBytes(byte[] str, int blocksize){ | |
byte[] barr; | |
if (str.length > blocksize){ | |
int padbytes = str.length % blocksize ; | |
barr = new byte[str.length + (blocksize-padbytes)]; | |
}else{ | |
barr = new byte[blocksize]; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int encrypt( | |
void* buffer, | |
int buffer_len, | |
char* IV, | |
char* key, | |
int key_len | |
){ | |
MCRYPT td = mcrypt_module_open("rijndael-128", NULL, "cbc", NULL); | |
int blocksize = mcrypt_enc_get_block_size(td); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static byte[] encrypt(String plainText, String encryptionKey, String IV) throws Exception { | |
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding", "SunJCE"); | |
SecretKeySpec key = new SecretKeySpec(encryptionKey.getBytes("UTF-8"), "AES"); | |
cipher.init(Cipher.ENCRYPT_MODE, key,new IvParameterSpec(IV.getBytes("UTF-8"))); | |
return cipher.doFinal(plainText.getBytes("UTF-8")); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
/* | |
* MCrypt API available online: | |
* http://linux.die.net/man/3/mcrypt | |
*/ | |
#include <mcrypt.h> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bottle import route, run | |
@route('/hello') | |
def hello(): | |
return "Hello World!" | |
application = bottle.default_app() | |
if __name__ == "__main__: | |
run(host='localhost', port=8080, debug=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# to create a visualisation, run like this: | |
# | |
# ./timeline.py --dot | dot -Tpng > filename.png | |
# | |
import sys |