2022-04-22 16:53:40 +08:00
|
|
|
package starcrypto
|
|
|
|
|
|
|
|
|
|
import (
|
2026-03-14 15:39:21 +08:00
|
|
|
"b612.me/starcrypto/asymm"
|
2022-04-22 16:53:40 +08:00
|
|
|
"crypto"
|
|
|
|
|
"crypto/rsa"
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-10 13:04:26 +08:00
|
|
|
func GenerateRsaKey(bits int) (*rsa.PrivateKey, *rsa.PublicKey, error) {
|
2026-03-14 15:39:21 +08:00
|
|
|
return asymm.GenerateRsaKey(bits)
|
2022-04-22 16:53:40 +08:00
|
|
|
}
|
|
|
|
|
|
2024-03-10 13:04:26 +08:00
|
|
|
func EncodeRsaPrivateKey(private *rsa.PrivateKey, secret string) ([]byte, error) {
|
2026-03-14 15:39:21 +08:00
|
|
|
return asymm.EncodeRsaPrivateKey(private, secret)
|
2022-04-22 16:53:40 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-18 13:43:18 +08:00
|
|
|
func EncodeRsaPrivateKeyWithLegacy(private *rsa.PrivateKey, secret string, legacy bool) ([]byte, error) {
|
|
|
|
|
return asymm.EncodeRsaPrivateKeyWithLegacy(private, secret, legacy)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func EncodeRsaPrivateKeyPKCS8(private *rsa.PrivateKey, secret string) ([]byte, error) {
|
|
|
|
|
return asymm.EncodeRsaPrivateKeyPKCS8(private, secret)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-10 13:04:26 +08:00
|
|
|
func EncodeRsaPublicKey(public *rsa.PublicKey) ([]byte, error) {
|
2026-03-14 15:39:21 +08:00
|
|
|
return asymm.EncodeRsaPublicKey(public)
|
2022-04-22 16:53:40 +08:00
|
|
|
}
|
|
|
|
|
|
2024-03-10 13:04:26 +08:00
|
|
|
func DecodeRsaPrivateKey(private []byte, password string) (*rsa.PrivateKey, error) {
|
2026-03-14 15:39:21 +08:00
|
|
|
return asymm.DecodeRsaPrivateKey(private, password)
|
2022-04-22 16:53:40 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-18 13:43:18 +08:00
|
|
|
func DecodeRsaPrivateKeyWithLegacy(private []byte, password string, legacy bool) (*rsa.PrivateKey, error) {
|
|
|
|
|
return asymm.DecodeRsaPrivateKeyWithLegacy(private, password, legacy)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DecodeRsaPrivateKeyPKCS8(private []byte, password string) (*rsa.PrivateKey, error) {
|
|
|
|
|
return asymm.DecodeRsaPrivateKeyPKCS8(private, password)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-10 13:04:26 +08:00
|
|
|
func DecodeRsaPublicKey(pubStr []byte) (*rsa.PublicKey, error) {
|
2026-03-14 15:39:21 +08:00
|
|
|
return asymm.DecodeRsaPublicKey(pubStr)
|
2022-04-22 16:53:40 +08:00
|
|
|
}
|
|
|
|
|
|
2024-03-10 13:04:26 +08:00
|
|
|
func EncodeRsaSSHPublicKey(public *rsa.PublicKey) ([]byte, error) {
|
2026-03-14 15:39:21 +08:00
|
|
|
return asymm.EncodeRsaSSHPublicKey(public)
|
2022-04-22 16:53:40 +08:00
|
|
|
}
|
|
|
|
|
|
2024-03-10 13:04:26 +08:00
|
|
|
func GenerateRsaSSHKeyPair(bits int, secret string) (string, string, error) {
|
2026-03-14 15:39:21 +08:00
|
|
|
return asymm.GenerateRsaSSHKeyPair(bits, secret)
|
2022-04-22 16:53:40 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-18 13:43:18 +08:00
|
|
|
func GenerateRsaSSHKeyPairWithLegacy(bits int, secret string, legacy bool) (string, string, error) {
|
|
|
|
|
return asymm.GenerateRsaSSHKeyPairWithLegacy(bits, secret, legacy)
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 16:53:40 +08:00
|
|
|
func RSAEncrypt(pub *rsa.PublicKey, data []byte) ([]byte, error) {
|
2026-03-14 15:39:21 +08:00
|
|
|
return asymm.RSAEncrypt(pub, data)
|
2022-04-22 16:53:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func RSADecrypt(prikey *rsa.PrivateKey, data []byte) ([]byte, error) {
|
2026-03-14 15:39:21 +08:00
|
|
|
return asymm.RSADecrypt(prikey, data)
|
2022-04-22 16:53:40 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-18 13:43:18 +08:00
|
|
|
func RSAEncryptOAEP(pub *rsa.PublicKey, data, label []byte, hashType crypto.Hash) ([]byte, error) {
|
|
|
|
|
return asymm.RSAEncryptOAEP(pub, data, label, hashType)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func RSADecryptOAEP(prikey *rsa.PrivateKey, data, label []byte, hashType crypto.Hash) ([]byte, error) {
|
|
|
|
|
return asymm.RSADecryptOAEP(prikey, data, label, hashType)
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 16:53:40 +08:00
|
|
|
func RSASign(msg, priKey []byte, password string, hashType crypto.Hash) ([]byte, error) {
|
2026-03-14 15:39:21 +08:00
|
|
|
return asymm.RSASign(msg, priKey, password, hashType)
|
2022-04-22 16:53:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func RSAVerify(data, msg, pubKey []byte, hashType crypto.Hash) error {
|
2026-03-14 15:39:21 +08:00
|
|
|
return asymm.RSAVerify(data, msg, pubKey, hashType)
|
2022-04-22 16:53:40 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-18 13:43:18 +08:00
|
|
|
func RSASignPSS(msg, priKey []byte, password string, hashType crypto.Hash, opts *rsa.PSSOptions) ([]byte, error) {
|
|
|
|
|
return asymm.RSASignPSS(msg, priKey, password, hashType, opts)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func RSAVerifyPSS(sig, msg, pubKey []byte, hashType crypto.Hash, opts *rsa.PSSOptions) error {
|
|
|
|
|
return asymm.RSAVerifyPSS(sig, msg, pubKey, hashType, opts)
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-22 16:53:40 +08:00
|
|
|
func RSAEncryptByPrivkey(privt *rsa.PrivateKey, data []byte) ([]byte, error) {
|
2026-03-14 15:39:21 +08:00
|
|
|
return asymm.RSAEncryptByPrivkey(privt, data)
|
2022-04-22 16:53:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func RSADecryptByPubkey(pub *rsa.PublicKey, data []byte) ([]byte, error) {
|
2026-03-14 15:39:21 +08:00
|
|
|
return asymm.RSADecryptByPubkey(pub, data)
|
2022-04-22 16:53:40 +08:00
|
|
|
}
|