package apicrypt import ( "PaymentCenter/app/constants/errorcode" "PaymentCenter/app/models/appmodel" "PaymentCenter/app/utils/encrypt/rsa" ) func NewRsa(app *appmodel.App) ApiCrypt { return &Rsa{ App: app, } } func (r *Rsa) Encrypt(decryptData string) (encryptData []byte, errCode int) { if r.App.MerchantPublicKey == "" { return nil, errorcode.AppRsaEncryptKeyNotFound } // encryptData, err := rsa.Encrypt(r.App.MerchantPublicKey, []byte(decryptData)) if err != nil { return nil, errorcode.AppRsaEncryptFail } return } func (r *Rsa) Decrypt(encryptData string) (decryptData []byte, errCode int) { if r.App.PrivateKey == "" { return nil, errorcode.AppRsaDecryptKeyNotFound } decryptData, err := rsa.Decrypt(r.App.PrivateKey, encryptData) if err != nil { return nil, errorcode.AppRsaDecryptFail } return }