Exemplo n.º 1
0
// Encrypt encrypts the response using the provided hex encoded public key
func (d *DebugResponse) Encrypt(pubKey string) error {
	if pubKey == "" {
		return fmt.Errorf("pubKey must be supplied")
	}

	pk := new([32]byte)
	dpk, err := hex.DecodeString(pubKey)
	if err != nil {
		lg.Fatalln("Could not decode debug public key")
	}
	copy(pk[:], dpk[:32])
	data, err := json.Marshal(&d)
	if err != nil {
		lg.Errorln("could not marshal debug response", err)
		return nil
	}

	encrypted, err := sodiumbox.Seal(data, pk)
	if err != nil {
		lg.Errorln("could not encrypt debug response", err)
		return nil
	}

	*d = DebugResponse{
		Header:    d.Header,
		Encrypted: hex.EncodeToString(encrypted.Box),
	}

	return nil

}
Exemplo n.º 2
0
Arquivo: dotp.go Projeto: mdp/go-dotp
// CreateChallenge is what it is
func CreateChallenge(otp, name, recipientPubID string) (*Challenge, error) {
	publicKey, err := GetPublicKeyFromPublicID(recipientPubID)
	if err != nil {
		return nil, err
	}
	msg, err := sodiumbox.Seal([]byte(name+"|"+otp), publicKey)
	if err != nil {
		return nil, err
	}
	return &Challenge{
		OTP:     otp,
		Name:    name,
		Crypted: *msg,
	}, nil
}