initial
This commit is contained in:
commit
25072e31d8
1 changed files with 45 additions and 0 deletions
45
app.go
Normal file
45
app.go
Normal 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])
|
||||
}
|
Loading…
Reference in a new issue