Skip to content

Instantly share code, notes, and snippets.

@xqus
xqus / new.php
Created November 7, 2011 16:59
phpSec key history
<?php
/* Check key size. */
$keySize = strlen($key);
$keySizes = mcrypt_enc_get_supported_key_sizes($td);
if(count($keySizes) > 0) {
/* Encryption method requires a specific key size. */
if(!in_array($keySize, $keySizes)) {
phpsec::error('Key is out of range. Should be one of: '. var_export($keySizes ,1));
return false;
}
<?php
/**
* Inject a salt into a password to create the string to be hashed.
* @author Audun Larsen <larsen@xqus.com>
*
* @param string $password
* Plain-text password.
*
* @param string $salt
* Well, the salt to inject into the password.
@xqus
xqus / gist:1074931
Created July 10, 2011 20:21
Creating an encryption key from a secret using PHP
<?php
/**
* Get a key from a secret.
* What we do is create two different hashes from the secret, combine them
* and pick out the number of characters we need.
* We used the raw binary output of the hash function for maximum
* bit strength (we have 255 chars to choose from, instead of 16).
*
* @param string $secret
* The secret to generate a key from.
@xqus
xqus / SHA_256.php
Created February 26, 2011 10:46
Grunnleggende kryptografi for webutviklere
<?php
echo hash('sha256', 'my password');
/* Produserer: bb14292d91c6d0920a5536bb41f3a50f66351b7b9d94c804dfce8a96ca1051f2 */
<?php
/* Set up array with options for the context used by file_get_contents(). */
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"User-Agent: phpSec (http://phpsec.xqus.com)\r\n"
)
);
<?php
/**
Copyright 2011 Audun Larsen. All rights reserved.
larsen@xqus.com
Redistribution and use, with or without modification,
are permitted provided that the following condition is met:
* Redistribution and use of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.