Advertisement
t_a_w

key decoder

Mar 24th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.91 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require "base64"
  4. require "openssl"
  5.  
  6. # For private key:
  7. # version           Version,
  8. # modulus           INTEGER,  -- n
  9. # publicExponent    INTEGER,  -- e
  10. # privateExponent   INTEGER,  -- d
  11. # prime1            INTEGER,  -- p
  12. # prime2            INTEGER,  -- q
  13. # exponent1         INTEGER,  -- d mod (p-1)
  14. # exponent2         INTEGER,  -- d mod (q-1)
  15. # coefficient       INTEGER,  -- (inverse of q) mod p
  16. #
  17. # where n=pq, d=(inverse of e) mod n
  18.  
  19. # For public key:
  20. # modulus           INTEGER,  -- n
  21. # publicExponent    INTEGER,  -- e
  22.  
  23. def print_asn(d, prefix="")
  24.   case d
  25.   when OpenSSL::ASN1::Sequence
  26.     puts "#{prefix}Sequence:"
  27.     d.value.each do |item|
  28.       print_asn item, "#{prefix}  "
  29.     end
  30.   when OpenSSL::ASN1::Integer
  31.     puts "#{prefix}#{d.value}"
  32.   else
  33.     raise
  34.   end
  35. end
  36.  
  37. data = STDIN.read
  38. data = Base64.decode64(data)
  39.  
  40. print_asn OpenSSL::ASN1.decode(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement