//Build sets params in record from args and return id.
func (r *Record) Build(stamp int64, body map[string]string, passwd string) string {
	r.contents = make(map[string]string)
	r.Stamp = stamp
	for key, value := range body {
		if value == "" {
			continue
		}
		r.contents[key] = value
		r.keyOrder = append(r.keyOrder, key)
	}
	if passwd != "" {
		k, err := util.MakePrivateKey(passwd)
		if err == nil {
			pubkey, _ := k.GetKeys()
			md := util.MD5digest(r.bodystr())
			sign := k.Sign(md)
			r.contents["pubkey"] = pubkey
			r.contents["sign"] = sign
			r.contents["target"] = strings.Join(r.keyOrder, ",")
			r.keyOrder = append(r.keyOrder, "pubkey")
			r.keyOrder = append(r.keyOrder, "sign")
			r.keyOrder = append(r.keyOrder, "target")
		}
	}

	id := util.MD5digest(r.bodystr())
	r.ID = id
	return r.ID
}
//md5check return true if md5 of bodystr is same as r.id.
func (r *Record) md5check() bool {
	return util.MD5digest(r.bodystr()) == r.ID
}