Example #1
0
// Chap-Password = id + md5(id|password|challenge)
func enChapPassword(password []byte, challenge []byte) []byte {
	id := []byte{challenge[15]}

	md5 := md5.New()

	md5.Write(id[:])
	md5.Write(password)
	md5.Write(challenge)

	return append(id[:], md5.Sum(nil)...)
}
Example #2
0
func GenNameUUID(name string) string {
	md5 := md5.New()
	md5.Write([]byte(name))
	md5Sum := md5.Sum(nil)
	md5Sum[6] &= 0x0F
	md5Sum[6] |= 0x30
	md5Sum[8] &= 0x3F
	md5Sum[8] |= 0x80
	return hex.EncodeToString(md5Sum)
}
Example #3
0
func enPapPassword(auth PktAuth, secret []byte, password []byte) []byte {
	me := papPassword(password)

	crypt := []byte(nil)
	count := me.Count()
	var b = make([][papBlockSize]byte, count)
	var c = make([][papBlockSize]byte, count)

	for i := 0; i < count; i++ {
		md5 := md5.New()

		md5.Write(secret)
		md5.Write(auth)

		copy(b[i][:], md5.Sum(nil))
		xor(c[i][:], me.Block(i), b[i][:])
		crypt = append(crypt, c[i][:]...)
	}

	return crypt
}
func genFileShas(filename string) (string, string, string, error) {
	data, err := ioutil.ReadFile(filename)
	if err != nil {
		return "", "", "", fmt.Errorf("could not compute file '%s' checksum: %s", filename, err)
	}
	h := sha1.New()
	h.Write([]byte(data))
	sha1 := hex.EncodeToString(h.Sum(nil))

	h256 := sha256.New()
	h256.Write([]byte(data))
	shaSum := h256.Sum(nil)
	sha256base64 := base64.StdEncoding.EncodeToString(shaSum[:])

	md5 := md5.New()
	md5.Write([]byte(data))
	md5Sum := hex.EncodeToString(md5.Sum(nil))

	return sha1, sha256base64, md5Sum, nil
}
Example #5
0
func bytesFromDir(dir, suffix string) ([]byte, []byte) {

	var buf *bytes.Buffer = &bytes.Buffer{}
	md5 := md5.New()

	files, _ := ioutil.ReadDir(dir)
	for _, f := range files {
		if strings.HasSuffix(f.Name(), suffix) {

			if b, err := ioutil.ReadFile(filepath.Join(dir, f.Name())); err != nil {
				logger.Println(err)
				logger.Printf("unable tor read file: %s, '%s', skipping", f.Name(), err)
			} else {
				buf.Write(b)
				md5.Write(b)
			}

		}
	}
	return buf.Bytes(), md5.Sum(nil)

}
Example #6
0
func Solve() {
	md5 := md5.New()
	key := "bgvyzdsv"
	i := 1

	for {
		data := []byte(key + strconv.Itoa(i))

		md5.Write(data)
		hash := fmt.Sprintf("%x\n", md5.Sum(nil))
		i++
		md5.Reset()

		if hash[0:5] == "00000" {
			fmt.Println("Five zeroes", string(data), hash)
		}

		if hash[0:6] == "000000" {
			fmt.Println("Six zeroes", string(data), hash)
			return
		}
	}
}
Example #7
0
func checksumProcessPath(directory string, name string, deleteMode bool, workingDirectory string) {
	directory = fpath.Clean(directory)
	baseFilename := fpath.Join(directory, name+".")
	ffpFilename := baseFilename + "ffp"
	md5Filename := baseFilename + "md5"

	// If we're in delete mode, let's just delete the ffp and md5 files right away
	if deleteMode {
		removeFile(ffpFilename, true)
		removeFile(md5Filename, true)
		return
	}

	// Let's create an md5 file buffer and
	// a pool to store files to be in the ffp
	var md5Buffer bytes.Buffer
	ffpPool := []string{
		// The first arg for ffpPool is this
		// because we're going to dump the entire
		// pool in the command later
		"--show-md5sum",
	}

	// This walks through every file in the folder
	fpath.Walk(directory,
		func(path string, info os.FileInfo, err error) error {
			if err != nil {
				fmt.Println("!!Encountered error for: " + path)
				fmt.Println("!!This is the message: " + err.Error())
				return nil
			} else if info.IsDir() {
				// We don't care about directories either,
				// so let's jump out of here
				return nil
			}

			if (path == ffpFilename) || (path == md5Filename) {
				// ffpFilename is hashed afterwards
				// and we don't need to hash ourself either
				return nil
			}

			name := strings.TrimPrefix(
				path,
				directory+"\\",
			)

			if fpath.Ext(path) == ".flac" {
				// So if the file we have is an ffp file,
				// lets add it to the pool to be checked!
				ffpPool = append(ffpPool, name)
			}

			// Read the file
			data, err := ioutil.ReadFile(path)

			if err != nil {
				fmt.Println("!!Encountered error for: " + path)
				fmt.Println("!!This is the message: " + err.Error())
			}

			md5Buffer.WriteString(checksumFormatMD5(md5.Sum(data), name))
			return nil
		},
	)

	// If the pool contains atleast one **filename**
	// the first item in the pool is actually just a flag!
	if len(ffpPool) > 1 {
		cmd := exec.Command(fpath.Join(workingDirectory, "metaflac"), ffpPool[:]...)
		cmd.Dir = directory

		data, err := cmd.Output()
		if err != nil {
			fmt.Println("metaflac returned an invalid response")
			if data != nil {
				fmt.Println(data)
			}
			panic(err)
		}

		// The md5 buffer doesn't contain our ffp file, so let's write that to the buffer
		md5Buffer.WriteString(checksumFormatMD5(md5.Sum(data), name+".ffp"))

		// Let's write the ffp file now
		ffp, err := os.Create(ffpFilename)
		defer ffp.Close()

		if err != nil {
			fmt.Println("!!Could not create ffp file: " + ffpFilename)
			fmt.Println("!!Error: " + err.Error())
		} else {
			ffp.Write(data)
		}
	}

	// If the md5buffer isn't empty
	if md5Buffer.Len() > 0 {
		// Let's write the md5 file
		md5, err := os.Create(md5Filename)
		defer md5.Close()

		if err != nil {
			fmt.Println("!!Could not create md5 file: " + md5Filename)
			fmt.Println("!!Error: " + err.Error())
		} else {
			md5.Write(md5Buffer.Bytes())
		}
	}

	fmt.Println("Done with", directory)
}
Example #8
0
// Login is synchronized. Set timeout in millisecond.
func (t *Connection) Login(clientID string, secret string,
	timeout time.Duration) (err error) {
	glog.Infof("Login %s secret %s", clientID, secret)
	// ClientID
	b, err := octetString(clientID, 8)
	if err != nil {
		return
	}
	body := bytes.NewBuffer(b)
	// AuthenticatorClient
	// MD5(ClientID + 7 字节的二进制 0(0x00) + Shared secret + Timestamp)
	md5 := md5.New()
	_, err = io.WriteString(md5, clientID)
	if err != nil {
		return
	}
	_, err = md5.Write([]byte{0, 0, 0, 0, 0, 0, 0})
	if err != nil {
		return
	}
	_, err = io.WriteString(md5, secret)
	if err != nil {
		return
	}
	timestamp := getTimestamp()
	_, err = io.WriteString(md5, timestamp)
	if err != nil {
		return
	}
	ac := md5.Sum(nil)
	glog.V(1).Infof("AuthenticatorClient 0x%x", ac)
	_, err = body.Write(ac)
	if err != nil {
		return
	}
	// login mode
	err = body.WriteByte(LOGIN_MODE_SEND)
	if err != nil {
		return
	}
	// timestamp in uint32
	its, err := strconv.ParseUint(timestamp, 10, 32)
	if err != nil {
		return
	}
	err = binary.Write(body, binary.BigEndian, uint32(its))
	if err != nil {
		return
	}
	// version
	err = body.WriteByte(VERSION)
	if err != nil {
		return
	}
	seq, err := t.writeRequest(REQID_LOGIN, body.Bytes())
	if err != nil {
		return
	}
	c := make(chan int)
	t.pool[seq] = &loginReq{
		Secret: secret,
		AC:     ac,
		Sync:   c,
	}
	// wait for respond
	select {
	case c <- 1:
	case <-time.After(timeout):
		err = errors.New("Login timed out")
		close(c)
	}
	return
}
Example #9
0
func encodeKey(key []byte) []byte {

	md5 := md5.New()
	md5.Write(key)
	return md5.Sum(nil)
}
Example #10
0
func MD5Sum(in string) string {
	md5 := md5.New()
	md5.Write([]byte(in))
	return fmt.Sprintf("%x", md5.Sum(nil))
}
Example #11
0
// Hash generates a MD5 hash based on current ID and a suffix string.
func (v ID) Hash(suffix []byte) []byte {
	md5 := md5.New()
	md5.Write(v[:])
	md5.Write(suffix)
	return md5.Sum(nil)
}
Example #12
0
func calcMd5(s []byte) string {
	md5 := md5.New()
	md5.Write(s)
	return fmt.Sprintf("%x", md5.Sum(nil))
}
Example #13
0
func md5sum(data []byte) []byte {
	md5 := md5.New()
	md5.Write(data)
	return md5.Sum(nil)
}