github.com/cyverse/go-irodsclient@v0.13.2/irods/auth/native.go (about) 1 package auth 2 3 import ( 4 "crypto/md5" 5 "encoding/base64" 6 7 "github.com/cyverse/go-irodsclient/irods/common" 8 ) 9 10 const ( 11 challengeLen int = 64 12 authResponseLen int = 16 13 ) 14 15 // GenerateAuthResponse returns auth response 16 func GenerateAuthResponse(challenge []byte, password string) string { 17 paddedPassword := make([]byte, common.MaxPasswordLength) 18 copy(paddedPassword, []byte(password)) 19 20 m := md5.New() 21 m.Write(challenge[:challengeLen]) 22 m.Write(paddedPassword) 23 encodedPassword := m.Sum(nil) 24 25 // replace 0x00 to 0x01 26 for idx := 0; idx < len(encodedPassword); idx++ { 27 if encodedPassword[idx] == 0 { 28 encodedPassword[idx] = 1 29 } 30 } 31 32 b64encodedPassword := base64.StdEncoding.EncodeToString(encodedPassword[:authResponseLen]) 33 return b64encodedPassword 34 }