From b1506a2b09caf27562cf1d49d40d3204263fba13 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Fri, 8 Sep 2017 10:19:04 +0200 Subject: [PATCH] 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. --- pkg/util/encryption.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/util/encryption.go b/pkg/util/encryption.go index 2f8b5d7af56..d41665bafd6 100644 --- a/pkg/util/encryption.go +++ b/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) {