pcrypto: fix

This commit is contained in:
fatedier 2016-04-05 15:40:32 +08:00
parent b3ee746be8
commit 718e707b77
2 changed files with 18 additions and 4 deletions

View File

@ -209,7 +209,7 @@ func PipeDecrypt(r net.Conn, w net.Conn, key string) error {
return err return err
} }
res, err := laes.Decrypto(buf) res, err := laes.Decrypt(buf)
if err != nil { if err != nil {
log.Error("Decrypt [%s] error, %v", string(buf), err) log.Error("Decrypt [%s] error, %v", string(buf), err)
return fmt.Errorf("Decrypt [%s] error: %v", string(buf), err) return fmt.Errorf("Decrypt [%s] error: %v", string(buf), err)
@ -239,7 +239,7 @@ func PipeEncrypt(r net.Conn, w net.Conn, key string) error {
if err != nil { if err != nil {
return err return err
} }
res, err := laes.Encrypto(buf[:n]) res, err := laes.Encrypt(buf[:n])
if err != nil { if err != nil {
log.Error("Encrypt error: %v", err) log.Error("Encrypt error: %v", err)
return fmt.Errorf("Encrypt error: %v", err) return fmt.Errorf("Encrypt error: %v", err)

View File

@ -1,3 +1,17 @@
// Copyright 2016 fatedier, fatedier@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package pcrypto package pcrypto
import ( import (
@ -25,7 +39,7 @@ func (pc *Pcrypto) Init(key []byte) error {
return err return err
} }
func (pc *Pcrypto) Encrypto(src []byte) ([]byte, error) { func (pc *Pcrypto) Encrypt(src []byte) ([]byte, error) {
// gzip // gzip
var zbuf bytes.Buffer var zbuf bytes.Buffer
zwr, err := gzip.NewWriterLevel(&zbuf, -1) zwr, err := gzip.NewWriterLevel(&zbuf, -1)
@ -49,7 +63,7 @@ func (pc *Pcrypto) Encrypto(src []byte) ([]byte, error) {
return []byte(base64.StdEncoding.EncodeToString(crypted)), nil return []byte(base64.StdEncoding.EncodeToString(crypted)), nil
} }
func (pc *Pcrypto) Decrypto(str []byte) ([]byte, error) { func (pc *Pcrypto) Decrypt(str []byte) ([]byte, error) {
// base64 // base64
data, err := base64.StdEncoding.DecodeString(string(str)) data, err := base64.StdEncoding.DecodeString(string(str))
if err != nil { if err != nil {