-
Notifications
You must be signed in to change notification settings - Fork 54
/
sign.go
52 lines (43 loc) · 947 Bytes
/
sign.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
43
44
45
46
47
48
49
50
51
52
package main
import (
"crypto/x509"
"encoding/pem"
"github.com/moov-io/signedxml"
"log"
"os"
)
func main() {
log.Println("USigner 1.0.0")
log.Println("Reading private key...")
rawKey, err := os.ReadFile("keys/mod/priv.key")
if err != nil {
log.Fatal(err)
}
blockKey, _ := pem.Decode(rawKey)
key, err := x509.ParsePKCS1PrivateKey(blockKey.Bytes)
if err != nil {
panic(err)
}
log.Println("Reading license.xml...")
lic, err := os.ReadFile("license.xml")
if err != nil {
panic(err)
}
log.Println("Creating XML signer instance...")
signer, err := signedxml.NewSigner(string(lic))
if err != nil {
panic(err)
}
log.Println("Signing...")
signer.SetReferenceIDAttribute("id")
signedXML, err := signer.Sign(key)
if err != nil {
panic(err)
}
log.Println("Writing Unity_lic.ulf...")
err = os.WriteFile("Unity_lic.ulf", []byte(signedXML), 0644)
if err != nil {
panic(err)
}
log.Println("Success, enjoy!")
}