Skip to content

Commit 5e829ab

Browse files
committed
Update mod and optimize rsa test code
1 parent bc12582 commit 5e829ab

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module codealg
1+
module github.com/quixote-liu/codealg
22

33
go 1.17
44

rsa.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func marshalPrivateKey(key *rsa.PrivateKey) ([]byte, error) {
9595
buf := bytes.NewBuffer(nil)
9696
stream := x509.MarshalPKCS1PrivateKey(key)
9797
err := pem.Encode(buf, &pem.Block{
98+
Type: "RSA PRIVATE KEY",
9899
Bytes: stream,
99100
})
100101
return buf.Bytes(), err
@@ -112,6 +113,7 @@ func marshalPublicKey(key *rsa.PublicKey) ([]byte, error) {
112113
buf := bytes.NewBuffer(nil)
113114
stream := x509.MarshalPKCS1PublicKey(key)
114115
err := pem.Encode(buf, &pem.Block{
116+
Type: "RSA PUBLIC KEY",
115117
Bytes: stream,
116118
})
117119
return buf.Bytes(), err

rsa_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,10 @@ func TestDecryptPKCS1v15(t *testing.T) {
217217
}
218218

219219
func TestGenerateKey(t *testing.T) {
220-
privateKey, publicKey, err := GenRSAKey(1024)
220+
privateKey, publicKey, err := GenRSAKey(2048)
221221
assert.Nil(t, err)
222222
assert.NotEmpty(t, privateKey)
223223
assert.NotEmpty(t, publicKey)
224+
// fmt.Println(string(privateKey))
225+
// fmt.Println(string(publicKey))
224226
}

0 commit comments

Comments
 (0)