2009-10-21 18:53:50 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package x509
|
|
|
|
|
|
|
|
import (
|
2009-11-05 17:44:02 -07:00
|
|
|
"big";
|
2009-10-21 18:53:50 -06:00
|
|
|
"crypto/rsa";
|
|
|
|
"encoding/pem";
|
|
|
|
"reflect";
|
|
|
|
"strings";
|
|
|
|
"testing";
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParsePKCS1PrivateKey(t *testing.T) {
|
|
|
|
block, _ := pem.Decode(strings.Bytes(pemPrivateKey));
|
|
|
|
priv, err := ParsePKCS1PrivateKey(block.Bytes);
|
|
|
|
if err != nil {
|
2009-11-09 13:07:39 -07:00
|
|
|
t.Errorf("Failed to parse private key: %s", err)
|
2009-10-21 18:53:50 -06:00
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(priv, rsaPrivateKey) {
|
2009-11-09 13:07:39 -07:00
|
|
|
t.Errorf("got:%+v want:%+v", priv, rsaPrivateKey)
|
2009-10-21 18:53:50 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var pemPrivateKey = `-----BEGIN RSA PRIVATE KEY-----
|
|
|
|
MIIBOgIBAAJBALKZD0nEffqM1ACuak0bijtqE2QrI/KLADv7l3kK3ppMyCuLKoF0
|
|
|
|
fd7Ai2KW5ToIwzFofvJcS/STa6HA5gQenRUCAwEAAQJBAIq9amn00aS0h/CrjXqu
|
|
|
|
/ThglAXJmZhOMPVn4eiu7/ROixi9sex436MaVeMqSNf7Ex9a8fRNfWss7Sqd9eWu
|
|
|
|
RTUCIQDasvGASLqmjeffBNLTXV2A5g4t+kLVCpsEIZAycV5GswIhANEPLmax0ME/
|
|
|
|
EO+ZJ79TJKN5yiGBRsv5yvx5UiHxajEXAiAhAol5N4EUyq6I9w1rYdhPMGpLfk7A
|
|
|
|
IU2snfRJ6Nq2CQIgFrPsWRCkV+gOYcajD17rEqmuLrdIRexpg8N1DOSXoJ8CIGlS
|
|
|
|
tAboUGBxTDq3ZroNism3DaMIbKPyYrAqhKov1h5V
|
|
|
|
-----END RSA PRIVATE KEY-----
|
|
|
|
`
|
|
|
|
|
|
|
|
func bigFromString(s string) *big.Int {
|
|
|
|
ret := new(big.Int);
|
|
|
|
ret.SetString(s, 10);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
var rsaPrivateKey = &rsa.PrivateKey{
|
|
|
|
PublicKey: rsa.PublicKey{
|
|
|
|
N: bigFromString("9353930466774385905609975137998169297361893554149986716853295022578535724979677252958524466350471210367835187480748268864277464700638583474144061408845077"),
|
|
|
|
E: 65537,
|
|
|
|
},
|
|
|
|
D: bigFromString("7266398431328116344057699379749222532279343923819063639497049039389899328538543087657733766554155839834519529439851673014800261285757759040931985506583861"),
|
|
|
|
P: bigFromString("98920366548084643601728869055592650835572950932266967461790948584315647051443"),
|
|
|
|
Q: bigFromString("94560208308847015747498523884063394671606671904944666360068158221458669711639"),
|
|
|
|
}
|