Skip to content

Instantly share code, notes, and snippets.

View zhangv's full-sized avatar
💭
I may be slow to respond.

V zhangv

💭
I may be slow to respond.
View GitHub Profile
@zhangv
zhangv / UrlShortener.php
Created May 10, 2018 03:22
UrlShortener
<?php
class UrlShortener{
private static $base = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';//the real base should not be easy to guess
private static $len = 5;
private $salt = 0; //simple salt strategy - just shift the base
public function __construct($salt = 0){
$this->salt = $salt;
}
@zhangv
zhangv / pkcs1topkcs8.php
Created January 28, 2018 09:50
convert RSA PKCS#1 to PKCS#8
function convertPKCS1toPKCS8($pkcs1){
$start_key = $pkcs1;
$start_key = str_replace('-----BEGIN RSA PUBLIC KEY-----', '', $start_key);
$start_key = trim(str_replace('-----END RSA PUBLIC KEY-----', '', $start_key));
$key = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' . str_replace("\n", '', $start_key);
$key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "\n-----END PUBLIC KEY-----";
return $key;
}