Exemplo n.º 1
0
// JSON encrypt the data and write response.
func (c *Context) SendJSON(data interface{}) error {
	encData, nonce, err := pp.Encrypt(data, c.Pubkey, c.ServSeckey)
	if err != nil {
		return err
	}

	res := pp.EncryptRes{
		Result:      pp.MakeResultWithCode(pp.ErrCode_Success),
		Encryptdata: encData,
		Nonce:       nonce,
	}
	return c.Resp.SendJSON(res)
}
Exemplo n.º 2
0
func encrypt(r interface{}, pubkey string, seckey string) (*pp.EncryptReq, error) {
	encData, nonce, err := pp.Encrypt(r, pubkey, seckey)
	if err != nil {
		return nil, err
	}

	s, err := cipher.SecKeyFromHex(seckey)
	if err != nil {
		return nil, err
	}

	p := cipher.PubKeyFromSecKey(s)
	return &pp.EncryptReq{
		Pubkey:      pp.PtrString(p.Hex()),
		Nonce:       nonce,
		Encryptdata: encData,
	}, nil
}