Skip to content

Instantly share code, notes, and snippets.

@psychocandy
Forked from Constellation/test.rb
Created July 13, 2012 19:51
Show Gist options
  • Save psychocandy/3107006 to your computer and use it in GitHub Desktop.
Save psychocandy/3107006 to your computer and use it in GitHub Desktop.
Extracting id from a crx package
require 'crxmake'
require 'digest/sha2'
# generate id from pem
def generate_id pkey
key = CrxMake::KEY + pkey.public_key.to_der
id = Digest::SHA256.hexdigest(key)
id[0..32].split('').map{|ch| ('a'.ord + ch.hex).chr }.join('')
end
File.open('path/to/pem.pem', 'rb') do |file|
puts generate_id OpenSSL::PKey::RSA.new(file)
end
# OR extract id from crx package
def extract_id file
content = file.read.force_encoding('ascii-8bit')
size = content[8...12].unpack('V')[0]
key = content[16, size]
id = Digest::SHA256.hexdigest(key)
id[0..32].split('').map{|ch| ('a'.ord + ch.hex).chr }.join('')
end
File.open('path/to/extension.crx', 'rb') do |file|
puts extract_id file
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment