浏览代码

securejson: decrypt should not modify src

When decrypting a source securejson byte array, should not
modify the source and now passes back a new dest byte array.
Daniel Lee 8 年之前
父节点
当前提交
b1506a2b09
共有 1 个文件被更改,包括 3 次插入2 次删除
  1. 3 2
      pkg/util/encryption.go

+ 3 - 2
pkg/util/encryption.go

@@ -27,12 +27,13 @@ func Decrypt(payload []byte, secret string) ([]byte, error) {
 	}
 	iv := payload[saltLength : saltLength+aes.BlockSize]
 	payload = payload[saltLength+aes.BlockSize:]
+	payloadDst := make([]byte, len(payload))
 
 	stream := cipher.NewCFBDecrypter(block, iv)
 
 	// XORKeyStream can work in-place if the two arguments are the same.
-	stream.XORKeyStream(payload, payload)
-	return payload, nil
+	stream.XORKeyStream(payloadDst, payload)
+	return payloadDst, nil
 }
 
 func Encrypt(payload []byte, secret string) ([]byte, error) {