Exemplo n.º 1
0
func encryptECDSA(in, out string, key *ecdsa.PublicKey, signkey string, local, armour bool) (err error) {
	message, err := ioutil.ReadFile(in)
	if err != nil {
		fmt.Println("[!]", err.Error())
		return
	}

	eciesKey := ecies.ImportECDSAPublic(key)
	eciesKey.Params = ecies.ParamsFromCurve(key.Curve)
	box, error := ecies.Encrypt(rand.Reader, eciesKey, message, nil, nil)
	if error != nil {
		fmt.Println("[!]", err.Error())
		return
	}
	pkg, err := packageBox(nil, box, armour)
	if err != nil {
		return
	}

	err = ioutil.WriteFile(out, pkg, 0644)
	if err != nil {
		fmt.Println("[!]", err.Error())
	}

	if err != nil {
		fmt.Println("[!]", err.Error())
	}
	return
}
Exemplo n.º 2
0
func decryptECDSA(in, out string, key *ecdsa.PrivateKey, verifykey string, armour bool) (err error) {
	pkg, err := ioutil.ReadFile(in)
	if err != nil {
		fmt.Println("[!]", err.Error())
		return
	}

	_, box, err := unpackageBox(pkg)
	if err != nil {
		return
	}

	eciesKey := ecies.ImportECDSA(key)
	eciesKey.PublicKey.Params = ecies.ParamsFromCurve(key.PublicKey.Curve)

	message, err := eciesKey.Decrypt(rand.Reader, box, nil, nil)
	if err != nil {
		fmt.Println("[!]", err.Error())
		return
	}
	err = ioutil.WriteFile(out, message, 0644)
	return
}