trying to set the pubkey from the private key

This commit is contained in:
Miek Gieben 2011-01-16 18:37:29 +01:00
parent 96457a435a
commit 2cfa45408d
3 changed files with 97 additions and 72 deletions

View File

@ -441,6 +441,26 @@ func (k *RR_DNSKEY) pubKeyRSA() *rsa.PublicKey {
return pubkey
}
// Set the public key (the value E and N)
func (k *RR_DNSKEY) setPubKeyRSA(_E int, _N *big.Int) {
println(_N)
buf := make([]byte, 2) // TODO(mg) length!
if _E < 256 {
buf[0] = 1
buf[1] = uint8(_E)
} else {
// length of _E? in bytes
// see keygen.go line 54
buf[0] = 0
//buf[1] = l1
//buf[2] = l2
// for length set _E
}
buf = append(buf, _N.Bytes()...)
k.PubKey = unpackBase64(buf)
return
}
// Map for algorithm names.
var alg_str = map[uint8]string{
AlgRSAMD5: "RSAMD5",

View File

@ -134,9 +134,11 @@ func (k *RR_DNSKEY) PrivateKeySetString(s string) (PrivateKey, os.Error) {
return nil, err
}
if right == "Modulus:" {
p.PublicKey.N = big.NewInt(0)
p.PublicKey.N.SetBytes(v)
}
if right == "PublicExponent:" { /* p.PublicKey.E */
p.PublicKey.E = 3
}
if right == "PrivateExponent:" {
p.D.SetBytes(v)
@ -158,5 +160,7 @@ func (k *RR_DNSKEY) PrivateKeySetString(s string) (PrivateKey, os.Error) {
}
line, _ = r.ReadBytes('\n')
}
k.setPubKeyRSA(p.PublicKey.E, p.PublicKey.N)
k.Algorithm = AlgRSASHA1 // ANDERS!
return p, nil
}

View File

@ -1,6 +1,6 @@
package dns
import ( "testing")
import ( "testing"; "fmt")
func TestConversion(t *testing.T) {
/*
@ -42,4 +42,5 @@ Activate: 20101221142359`
k := new(RR_DNSKEY)
p,_ := k.PrivateKeySetString(a)
p = p
fmt.Printf("%v\n", k)
}