service/library/mycrypto/cryptoService.go

44 lines
887 B
Go

package mycrypto
import (
"service/library/configcenter"
"service/library/logger"
"sync"
)
var (
instance *CryptoService
once sync.Once
)
func CryptoServiceInstance() *CryptoService {
once.Do(func() {
instance = &CryptoService{}
})
return instance
}
type CryptoService struct {
RSA *RsaCrypto
AES *AesCrypto
SHA256 *Sha256Crypto
}
func (cryptoService *CryptoService) Init(cryptoConfig *configcenter.CryptoConfig) (err error) {
if cryptoService.RSA, err = NewRsaCrypto(cryptoConfig); err != nil {
logger.Error("Init RSA Service failed! err:%v", err)
return
}
if cryptoService.AES, err = NewAesCrypto(cryptoConfig); err != nil {
logger.Error("Init AES Service failed! err:%v", err)
return
}
if cryptoService.SHA256, err = NewSha256Crypto(cryptoConfig); err != nil {
logger.Error("Init SHA256 Service failed! err:%v", err)
return
}
return
}