2016-11-21 16:51:05 -05:00
|
|
|
/*
|
2019-04-09 14:39:42 -04:00
|
|
|
* MinIO Cloud Storage, (C) 2016 MinIO, Inc.
|
2016-11-21 16:51:05 -05:00
|
|
|
*
|
|
|
|
* 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 cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/md5"
|
2021-02-24 12:00:15 -05:00
|
|
|
"crypto/sha256"
|
2016-11-21 16:51:05 -05:00
|
|
|
"encoding/hex"
|
|
|
|
)
|
|
|
|
|
2018-03-16 14:22:34 -04:00
|
|
|
// getSHA256Hash returns SHA-256 hash in hex encoding of given data.
|
2016-11-21 16:51:05 -05:00
|
|
|
func getSHA256Hash(data []byte) string {
|
2018-03-16 14:22:34 -04:00
|
|
|
return hex.EncodeToString(getSHA256Sum(data))
|
|
|
|
}
|
|
|
|
|
|
|
|
// getSHA256Hash returns SHA-256 sum of given data.
|
|
|
|
func getSHA256Sum(data []byte) []byte {
|
2016-11-21 16:51:05 -05:00
|
|
|
hash := sha256.New()
|
|
|
|
hash.Write(data)
|
2018-03-16 14:22:34 -04:00
|
|
|
return hash.Sum(nil)
|
2016-11-21 16:51:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// getMD5Sum returns MD5 sum of given data.
|
|
|
|
func getMD5Sum(data []byte) []byte {
|
|
|
|
hash := md5.New()
|
|
|
|
hash.Write(data)
|
|
|
|
return hash.Sum(nil)
|
|
|
|
}
|
|
|
|
|
2018-03-16 14:22:34 -04:00
|
|
|
// getMD5Hash returns MD5 hash in hex encoding of given data.
|
2016-11-21 16:51:05 -05:00
|
|
|
func getMD5Hash(data []byte) string {
|
|
|
|
return hex.EncodeToString(getMD5Sum(data))
|
|
|
|
}
|