-
-
Save psychocandy/3107006 to your computer and use it in GitHub Desktop.
Extracting id from a crx package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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