Skip to content

Instantly share code, notes, and snippets.

View scotttam's full-sized avatar

Scott Tamosunas scotttam

View GitHub Profile
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'base64'
require 'digest'
require 'openssl'
def encode(cryptkey, iv, cleardata)
cipher = OpenSSL::Cipher.new('AES-256-CBC')
cipher.encrypt # set cipher to be encryption mode
@scotttam
scotttam / apns.rb
Created January 31, 2012 15:51
Sends an Apple Push Notification with Ruby
require "rubygems"
require "yajl"
require "openssl"
require "socket"
device_token = '39cac56f 986a0e66 3c4fd4f4 68df5598 024d2ca3 8b9f307c 741c180e 9fc30c62'
device_token = device_token.gsub(" ", "")
the_byte_token = [device_token].pack("H*")
file = File.open("ruby_the_byte_token", "wb")
@scotttam
scotttam / decrypt.rb
Created March 17, 2011 14:56
decrypt PBKDF2/SHA1 and AES
require "base64"
require 'openssl'
require 'iconv'
CIPHER = "aes-256-cbc"
#http://www.ruby-doc.org/ruby-1.9/classes/OpenSSL/PKCS5.html
PASSPHRASE = "12345"
IV = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16].pack("c*")
@scotttam
scotttam / pbkdf2_aes.js
Created August 16, 2011 14:46
Javascript example generating a PBKDF2 key and encrypting/decrypting using AES/256/CBC
//Requires:
//JQuery
//slowAES (http://code.google.com/p/slowaes/)
//pbkdf2 (1.1) by Parvez Anandam (http://anandam.name/pbkdf2)
//sha1 (2.1a) by Paul Johnston (http://pajhome.org.uk/crypt/md5)
(function(window, document, $, undefined){
$(document).ready(function() {
var startTime = new Date();
@scotttam
scotttam / apns.py
Created January 30, 2012 21:21
Sends an Apple Push Notification with Python
import socket, ssl, json, struct
import binascii
# device token returned when the iPhone application
# registers to receive alerts
deviceToken = '39cac56f 986a0e66 3c4fd4f4 68df5598 024d2ca3 8b9f307c 741c180e 9fc30c62'
thePayLoad = {
'aps': {
'alert':'Oh no! Server\'s Down!',
@scotttam
scotttam / Decrypter.java
Created March 17, 2011 14:37
encrypt and decrypt with PBKDF2/SHA1 and AES
import javax.crypto.Cipher;
import java.security.spec.KeySpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.SecretKeyFactory;
import java.security.AlgorithmParameters;
import javax.crypto.spec.IvParameterSpec;
public class Decrypter {