2016-11-21 16:51:05 -05:00
|
|
|
/*
|
|
|
|
* Minio Cloud Storage, (C) 2016 Minio, Inc.
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
"encoding/base64"
|
|
|
|
"encoding/hex"
|
2016-12-19 22:32:55 -05:00
|
|
|
|
|
|
|
"github.com/minio/sha256-simd"
|
2016-11-21 16:51:05 -05:00
|
|
|
)
|
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
|
|
|
// getMD5HashBase64 returns MD5 hash in base64 encoding of given data.
|
|
|
|
func getMD5HashBase64(data []byte) string {
|
|
|
|
return base64.StdEncoding.EncodeToString(getMD5Sum(data))
|
|
|
|
}
|