| 
									
										
										
										
											2016-11-22 05:51:05 +08: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-20 11:32:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/minio/sha256-simd" | 
					
						
							| 
									
										
										
										
											2016-11-22 05:51:05 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // getSHA256Hash returns SHA-256 hash of given data.
 | 
					
						
							|  |  |  | func getSHA256Hash(data []byte) string { | 
					
						
							|  |  |  | 	hash := sha256.New() | 
					
						
							|  |  |  | 	hash.Write(data) | 
					
						
							|  |  |  | 	return hex.EncodeToString(hash.Sum(nil)) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // getMD5Sum returns MD5 sum of given data.
 | 
					
						
							|  |  |  | func getMD5Sum(data []byte) []byte { | 
					
						
							|  |  |  | 	hash := md5.New() | 
					
						
							|  |  |  | 	hash.Write(data) | 
					
						
							|  |  |  | 	return hash.Sum(nil) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // getMD5Hash returns MD5 hash of given data.
 | 
					
						
							|  |  |  | 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)) | 
					
						
							|  |  |  | } |