Skip to content

Instantly share code, notes, and snippets.

@weppos
Created December 7, 2013 18:59
Show Gist options
  • Save weppos/7847074 to your computer and use it in GitHub Desktop.
Save weppos/7847074 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"io/ioutil"
"os/exec"
"strings"
)
func opensslModulus(command string, content string) (string, error) {
cmd := exec.Command("openssl", command, "-noout", "-modulus")
cmd.Stdin = strings.NewReader(content)
out, err := cmd.Output()
if err != nil {
return "", err
}
return string(out), nil
}
func main() {
crt, err := ioutil.ReadFile("server.crt")
if err != nil {
panic(err)
}
key, err := ioutil.ReadFile("server.key")
if err != nil {
panic(err)
}
mkey, err := opensslModulus("x509", string(crt))
if err != nil {
panic(err)
}
mcrt, err := opensslModulus("rsa", string(key))
if err != nil {
panic(err)
}
fmt.Println(string(mkey))
fmt.Println(string(mcrt))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment