Created
June 22, 2017 16:40
-
-
Save davidbalbert/336e497b70bd43b9f6c5e6b323d887af to your computer and use it in GitHub Desktop.
Convert an RSA public key from PKCS#8 format to PKCS#1 format
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| # | |
| # Converts an RSA public key from PKCS#8 format to PKCS#1 format. This is useful if you don't have OpenSSL 1.1 | |
| # See https://stackoverflow.com/questions/18039401/how-can-i-transform-between-the-two-styles-of-public-key-format-one-begin-rsa | |
| key = STDIN.read | |
| lines = key.split("\n") | |
| only_key = lines[1..-2].join("") | |
| without_header = only_key[32..-1] | |
| new_key = without_header.chars.each_slice(64).map { |chars| chars.join }.join("\n") | |
| puts "-----BEGIN RSA PUBLIC KEY-----" | |
| puts new_key | |
| puts "-----END RSA PUBLIC KEY-----" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment