1
0
mirror of https://github.com/fumiama/tienyik.git synced 2026-06-04 23:10:26 +08:00

feat: add log & supporting packages

This commit is contained in:
源文雨
2025-10-30 23:23:45 +08:00
parent 617fc662c5
commit 15fcc9a338
19 changed files with 672 additions and 12 deletions

10
rsa.go
View File

@@ -7,19 +7,19 @@ import (
"encoding/base64"
)
type TYRSA rsa.PrivateKey
type RSA rsa.PrivateKey
func NewTYRSA() *TYRSA {
func NewRSA() *RSA {
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
panic(err)
}
privateKey.E = 0x010001
return (*TYRSA)(privateKey)
return (*RSA)(privateKey)
}
func (tyr *TYRSA) PublicKeyToSPKI() string {
func (tyr *RSA) PublicKeyToSPKI() string {
spkiBytes, err := x509.MarshalPKIXPublicKey(&tyr.PublicKey)
if err != nil {
panic(err)
@@ -27,6 +27,6 @@ func (tyr *TYRSA) PublicKeyToSPKI() string {
return base64.StdEncoding.EncodeToString(spkiBytes)
}
func (tyr *TYRSA) Decrypt(ciphertext []byte) ([]byte, error) {
func (tyr *RSA) Decrypt(ciphertext []byte) ([]byte, error) {
return rsa.DecryptPKCS1v15(rand.Reader, (*rsa.PrivateKey)(tyr), ciphertext)
}