"encoding/pem"
)
+var (
+ PublicKeyNoLoad = errors.New(`PublicKeyNoLoad`)
+ PrivateKeyNoLoad = errors.New(`PrivateKeyNoLoad`)
+)
+
type Crypto struct {
pubKey *rsa.PublicKey
priKey *rsa.PrivateKey
return
}
+func (t *Crypto) KeyStatus() (error) {
+ if t.pubKey == nil {
+ return PublicKeyNoLoad
+ }
+ if t.priKey == nil {
+ return PrivateKeyNoLoad
+ }
+ return nil
+}
+
func (t *Crypto) GetPKIXPubKey(pubPEMData []byte) (err error) {
block, _ := pem.Decode(pubPEMData)
if block == nil || block.Type != "PUBLIC KEY" {
func Test(t *testing.T){
var k Crypto
+ if k.KeyStatus() != PublicKeyNoLoad {t.Error(`Keystatus not PublicKeyNoLoad`)}
{
d,_ := FileLoad(`public.pem`)
k.GetPKIXPubKey(d)
}
+ if k.KeyStatus() != PrivateKeyNoLoad {t.Error(`Keystatus not PrivateKeyNoLoad`)}
{
d,_ := FileLoad(`private.pem`)
k.GetPKCS1PriKey(d)
}
+ if k.KeyStatus() != nil {t.Error(`Keystatus not nil`)}
if srcs,e := k.GetEncrypt([]byte(`1we23`));e != nil {
t.Error(e)
} else if des,e := k.GetDecrypt(srcs);e != nil {