]> 127.0.0.1 Git - part/.git/commitdiff
107 v0.4.9
authorqydysky <qydysky@foxmail.com>
Thu, 4 Mar 2021 08:37:18 +0000 (16:37 +0800)
committerqydysky <qydysky@foxmail.com>
Thu, 4 Mar 2021 08:37:18 +0000 (16:37 +0800)
crypto/Crypto.go
crypto/Crypto_test.go

index acbee35a77e828ac81dd918d7ffc7079007dd423..e634d607cda3ace58f21791578b964fd39dd37d4 100644 (file)
@@ -56,6 +56,15 @@ func (t *Crypto) GetPKIXPubKey(pubPEMData []byte) (err error) {
        return
 }
 
+func (t *Crypto) LoadPKIXPubKey(path string) (err error) {
+       if d,e := FileLoad(path);e != nil {
+               return e
+       } else {
+               err = t.GetPKIXPubKey(d)
+       }
+       return
+}
+
 func (t *Crypto) GetPKCS1PriKey(priPEMData []byte) (err error) {
        block, _ := pem.Decode(priPEMData)
        if block == nil || block.Type != "RSA PRIVATE KEY" {
@@ -68,6 +77,15 @@ func (t *Crypto) GetPKCS1PriKey(priPEMData []byte) (err error) {
        return
 }
 
+func (t *Crypto) LoadPKCS1PriKey(path string) (err error) {
+       if d,e := FileLoad(path);e != nil {
+               return e
+       } else {
+               err = t.GetPKCS1PriKey(d)
+       }
+       return
+}
+
 func (t *Crypto) GetEncrypt(sourceByte []byte) (tragetByte []byte, err error) {
        if t.pubKey == nil {
                err = errors.New(`public key not load`)
index 2f87acc81d1a0ae6c0ed88f3821a0d73bf3b3484..304e91998b5d00426f484103a404fff8d75d5416 100644 (file)
@@ -6,8 +6,7 @@ func Test(t *testing.T){
        var k Crypto
        if k.PubLoad() || k.PriLoad() {t.Error(`Keystatus not PublicKeyNoLoad`)}
        {
-               d,_ := FileLoad(`public.pem`)
-               k.GetPKIXPubKey(d)
+               k.LoadPKIXPubKey(`public.pem`)
        }
        if !k.PubLoad() || k.PriLoad() {t.Error(`Keystatus not PrivateKeyNoLoad`)}
        {
@@ -22,4 +21,8 @@ func Test(t *testing.T){
        } else {
                if s := string(des);s != `1we23` {t.Error(`not Match`,s)}
        }
+
+       if des,e := k.GetDecrypt([]byte(`1we23`));e == nil {
+               t.Error(des,e)
+       }
 }
\ No newline at end of file