Skip to content

Instantly share code, notes, and snippets.

@Constellation
Created July 11, 2012 17:17
Show Gist options
  • Save Constellation/3091823 to your computer and use it in GitHub Desktop.
Save Constellation/3091823 to your computer and use it in GitHub Desktop.
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