|
|
@ -14,7 +14,7 @@ |
|
|
|
* limitations under the License. |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
package keys |
|
|
|
package auth |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"crypto/rand" |
|
|
|
"crypto/rand" |
|
|
@ -24,9 +24,9 @@ import ( |
|
|
|
// Static alphaNumeric table used for generating unique keys
|
|
|
|
// Static alphaNumeric table used for generating unique keys
|
|
|
|
var alphaNumericTable = []byte("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") |
|
|
|
var alphaNumericTable = []byte("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ") |
|
|
|
|
|
|
|
|
|
|
|
// GenerateRandomAlphaNumeric - generate random alpha numeric value using only uppercase characters
|
|
|
|
// GenerateAccessKeyID - generate random alpha numeric value using only uppercase characters
|
|
|
|
// takes input as size in integer
|
|
|
|
// takes input as size in integer
|
|
|
|
func GenerateRandomAlphaNumeric(size int) ([]byte, error) { |
|
|
|
func GenerateAccessKeyID(size int) ([]byte, error) { |
|
|
|
alpha := make([]byte, size) |
|
|
|
alpha := make([]byte, size) |
|
|
|
_, err := rand.Read(alpha) |
|
|
|
_, err := rand.Read(alpha) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -39,13 +39,13 @@ func GenerateRandomAlphaNumeric(size int) ([]byte, error) { |
|
|
|
return alpha, nil |
|
|
|
return alpha, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GenerateRandomBase64 - generate random base64 numeric value from a random seed.
|
|
|
|
// GenerateSecretAccessKey - generate random base64 numeric value from a random seed.
|
|
|
|
func GenerateRandomBase64(size int) ([]byte, error) { |
|
|
|
func GenerateSecretAccessKey(size int) ([]byte, error) { |
|
|
|
rb := make([]byte, size) |
|
|
|
rb := make([]byte, size) |
|
|
|
_, err := rand.Read(rb) |
|
|
|
_, err := rand.Read(rb) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
dest := base64.StdEncoding.EncodeToString(rb) |
|
|
|
|
|
|
|
return []byte(dest), nil |
|
|
|
return []byte(base64.StdEncoding.EncodeToString(rb))[:size], nil |
|
|
|
} |
|
|
|
} |