github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/gomobile/walletutil/keycipher.go (about) 1 package walletutil 2 3 import ( 4 "fmt" 5 "github.com/sixexorg/magnetic-ring/crypto" 6 "github.com/sixexorg/magnetic-ring/crypto/cipher" 7 ) 8 9 func EncriptyKey(privk,pasw string) string { 10 cipher := cipher.NewCipher() 11 12 prk,err := crypto.HexToPrivateKey(privk) 13 if err != nil { 14 return newErrorResp(err.Error()) 15 } 16 17 pkbuf := prk.Bytes() 18 19 enbuf,err := cipher.Encrypt(pkbuf,[]byte(pasw)) 20 if err!=nil { 21 return newErrorResp(err.Error()) 22 } 23 encjson := fmt.Sprintf("%s",enbuf) 24 25 return newResp(fmt.Sprintf("%s", encjson)) 26 } 27 28 29 func DecriptyKey(encbuf,pasw string) string { 30 cipher := cipher.NewCipher() 31 32 prkbuf := []byte(encbuf) 33 34 35 debuf,err := cipher.Decrypt(prkbuf,[]byte(pasw)) 36 if err!=nil { 37 return newErrorResp(err.Error()) 38 } 39 encjson := fmt.Sprintf("%x",debuf) 40 41 return newResp(fmt.Sprintf("%s", encjson)) 42 }