key: finish key encoding and start cert

This commit is contained in:
Greg T. Wallace 2024-01-27 11:35:35 -05:00
parent 85462c93b1
commit 1f6dad4907
14 changed files with 592 additions and 115 deletions
pkg/pkcs15

24
pkg/pkcs15/private_key.go Normal file
View file

@ -0,0 +1,24 @@
package pkcs15
import "apc-p15-tool/pkg/tools/asn1obj"
// privateKeyObject returns the ASN.1 representation of a private key
func (p15 *pkcs15KeyCert) privateKeyObject() []byte {
// ensure all expected vals are available
p15.key.Precompute()
pkey := asn1obj.Sequence([][]byte{
// P
asn1obj.IntegerExplicitValue(3, p15.key.Primes[0]),
// Q
asn1obj.IntegerExplicitValue(4, p15.key.Primes[1]),
// Dp
asn1obj.IntegerExplicitValue(5, p15.key.Precomputed.Dp),
// Dq
asn1obj.IntegerExplicitValue(6, p15.key.Precomputed.Dq),
// Qinv
asn1obj.IntegerExplicitValue(7, p15.key.Precomputed.Qinv),
})
return pkey
}