-
Notifications
You must be signed in to change notification settings - Fork 34
/
genrsa.go
42 lines (38 loc) · 1008 Bytes
/
genrsa.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// This code requires a configuration file to initialize the crypto11
// library. Use the following config in a file named "crypto11.config"
//
// {
// "Path" : "/opt/cloudhsm/lib/libcloudhsm_pkcs11.so",
// "TokenLabel": "cavium",
// "Pin" : "$CRYPTO_USER:$PASSWORD"
// }
package main
import (
"fmt"
"log"
"time"
"github.com/ThalesIgnite/crypto11"
)
func main() {
p11Ctx, err := crypto11.ConfigureFromFile("crypto11.config")
if err != nil {
log.Fatal(err)
}
slots, err := p11Ctx.GetSlotList(true)
if err != nil {
log.Fatalf("Failed to list PKCS#11 Slots: %s", err.Error())
}
if len(slots) < 1 {
log.Fatal("No slot found")
}
for keySize := 2048; keySize <= 4096; keySize += 256 {
keyName := []byte(fmt.Sprintf("rsa%d-%d", keySize, time.Now().Unix()))
fmt.Printf("making %q: ", keyName)
rsakey, err := crypto11.GenerateRSAKeyPairOnSlot(slots[0], keyName, keyName, keySize)
if err != nil {
fmt.Printf("failed with %v\n", err)
} else {
fmt.Printf("%+v\n", rsakey)
}
}
}