Skip to content

Instantly share code, notes, and snippets.

{{#unless contentSent.license}}
<h3>WARNING: license not set</h3>
{{/unless}}
<script id="centralTemplate" type="text/x-handlebars-template">
<div class="central">{{contentSent}}</div>
</script>
@glynrob
glynrob / gist:7059295
Created October 19, 2013 18:01
Hashing in PHP
$md5 = md5($password.$salt);
echo "MD5 = $md5<br />";
$sha1 = sha1($password.$salt);
echo "SHA1 = $sha1<br />";
$sha512 = hash('sha512', $password.$salt);
echo "SHA512 = $sha512<br />";
@glynrob
glynrob / gist:7059316
Created October 19, 2013 18:03
Python hashing example
md5 = hashlib.md5()
md5.update(password+saltstring)
print 'MD5 = '+md5.hexdigest()
sha1string = hashlib.sha1(password + saltstring)
print 'SHA1 = '+sha1string.hexdigest()
sha1string = hashlib.sha512(password + saltstring)
print 'SHA512 = '+sha1string.hexdigest()
function public_encrypt($plaintext){
$fp=fopen("./mykey.pub","r");
$pub_key=fread($fp,8192);
fclose($fp);
openssl_get_publickey($pub_key);
openssl_public_encrypt($plaintext,$crypttext, $pub_key );
return(base64_encode($crypttext));
}
function private_decrypt($encryptedext){
rsa = RSA.load_pub_key("mykey.pub")
ctxt = rsa.public_encrypt(secretstring, RSA.pkcs1_padding)
encryptedText = ctxt.encode('base64')
print 'Encrypted Text = '+encryptedText
priv = RSA.load_key("mykey.pem")
decodeEncryptedText = encryptedText.decode('base64')
decryptedText = priv.private_decrypt(decodeEncryptedText, RSA.pkcs1_padding)
print 'Decrypted Text = '+decryptedText
/* POLYCRYPT HASH */
function polycryptHash(){
document.getElementById("polypassword").innerHTML=password;
var polystring=util.str2abv(password);
var op=window.polycrypt.digest("SHA-256",polystring);
op.oncomplete=function(e){
var hex=util.abv2hex(e.target.result);
document.getElementById("polyhash").innerHTML=hex;
}
op.onerror=function(e){
/* POLYCRYPT HASH */
function polycryptHash(){
var polystring=util.str2abv(password);
var op=window.polycrypt.digest("SHA-256",polystring);
op.oncomplete=function(e){
var hex=util.abv2hex(e.target.result);
// hex is the hash
}
}
window.polycrypt.onalive=polycryptHash;
// CRYPTOJS
var encrypted = CryptoJS.TripleDES.encrypt(secretString, password);
var decrypted = CryptoJS.TripleDES.decrypt(encrypted.toString(), password);
// SJCL
var encrypted = sjcl.encrypt(password, secretString);
var decrypted = sjcl.decrypt(password, encrypted);
@glynrob
glynrob / gist:7325774
Last active December 27, 2015 12:29
Underscore Template Example
<div class="page"></div>
<script type="text/template" id="title-template">
<br class="clear" />
<div class="row">
<h3><%= header %></h3>
</div>
</script>
<script>
var template = _.template($('#title-template').html(), {header:'COLLECTIONS'});