This commit is contained in:
Vincent Batts 2017-02-18 13:19:25 -05:00
commit 25072e31d8

45
app.go Normal file
View file

@ -0,0 +1,45 @@
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/sha1"
"crypto/x509"
"encoding/base32"
"encoding/pem"
"fmt"
"io"
"os"
"time"
)
var enc = base32.NewEncoding("abcdefghijklmnopqrstuvwxyz234567")
func main() {
pkey, err := rsa.GenerateKey(rand.Reader, 4096)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(pkey.D)
fmt.Printf("%v\n", pkey.D.Bytes())
// get the DER encoded key
data := x509.MarshalPKCS1PrivateKey(pkey)
fmt.Printf("%v\n", data)
b := pem.Block{
Bytes: data,
Type: "RSA PRIVATE KEY",
Headers: map[string]string{
"date": time.Now().String(),
},
}
data = pem.EncodeToMemory(&b)
fmt.Printf("%s\n", data)
h := sha1.New()
io.WriteString(h, "His money is twice tainted:")
sum := h.Sum(nil)
println(enc.EncodeToString(sum)[0:15])
}