starcrypto/rsa.go

60 lines
1.6 KiB
Go
Raw Normal View History

package starcrypto
import (
"b612.me/starcrypto/asymm"
"crypto"
"crypto/rsa"
)
2024-03-10 13:04:26 +08:00
func GenerateRsaKey(bits int) (*rsa.PrivateKey, *rsa.PublicKey, error) {
return asymm.GenerateRsaKey(bits)
}
2024-03-10 13:04:26 +08:00
func EncodeRsaPrivateKey(private *rsa.PrivateKey, secret string) ([]byte, error) {
return asymm.EncodeRsaPrivateKey(private, secret)
}
2024-03-10 13:04:26 +08:00
func EncodeRsaPublicKey(public *rsa.PublicKey) ([]byte, error) {
return asymm.EncodeRsaPublicKey(public)
}
2024-03-10 13:04:26 +08:00
func DecodeRsaPrivateKey(private []byte, password string) (*rsa.PrivateKey, error) {
return asymm.DecodeRsaPrivateKey(private, password)
}
2024-03-10 13:04:26 +08:00
func DecodeRsaPublicKey(pubStr []byte) (*rsa.PublicKey, error) {
return asymm.DecodeRsaPublicKey(pubStr)
}
2024-03-10 13:04:26 +08:00
func EncodeRsaSSHPublicKey(public *rsa.PublicKey) ([]byte, error) {
return asymm.EncodeRsaSSHPublicKey(public)
}
2024-03-10 13:04:26 +08:00
func GenerateRsaSSHKeyPair(bits int, secret string) (string, string, error) {
return asymm.GenerateRsaSSHKeyPair(bits, secret)
}
func RSAEncrypt(pub *rsa.PublicKey, data []byte) ([]byte, error) {
return asymm.RSAEncrypt(pub, data)
}
func RSADecrypt(prikey *rsa.PrivateKey, data []byte) ([]byte, error) {
return asymm.RSADecrypt(prikey, data)
}
func RSASign(msg, priKey []byte, password string, hashType crypto.Hash) ([]byte, error) {
return asymm.RSASign(msg, priKey, password, hashType)
}
func RSAVerify(data, msg, pubKey []byte, hashType crypto.Hash) error {
return asymm.RSAVerify(data, msg, pubKey, hashType)
}
func RSAEncryptByPrivkey(privt *rsa.PrivateKey, data []byte) ([]byte, error) {
return asymm.RSAEncryptByPrivkey(privt, data)
}
func RSADecryptByPubkey(pub *rsa.PublicKey, data []byte) ([]byte, error) {
return asymm.RSADecryptByPubkey(pub, data)
}