コード例 #1
0
func ExampleSignArmor62() {

	var err error

	// Make a new Keyring, initialized to be empty
	keyring := basic.NewKeyring()

	// The test message
	msg := []byte("The Magic Words are Squeamish Ossifrage")

	// Make a secret key for the sender
	var signer saltpack.SigningSecretKey
	signer, err = keyring.GenerateSigningKey()
	if err != nil {
		return
	}

	var signed string
	signed, err = saltpack.SignArmor62(msg, signer, "")
	if err != nil {
		return
	}

	// The verified message should match the input mesasge.
	var verifiedMsg []byte
	var signingPublicKey saltpack.SigningPublicKey
	signingPublicKey, verifiedMsg, _, err = saltpack.Dearmor62Verify(signed, keyring)
	if err != nil {
		return
	}

	if saltpack.PublicKeyEqual(signingPublicKey, signer.GetPublicKey()) {
		fmt.Println("The right key")
	}

	fmt.Println(string(verifiedMsg))

	// Output:
	// The right key
	// The Magic Words are Squeamish Ossifrage
}
コード例 #2
0
ファイル: key_test.go プロジェクト: mattcurrycom/client
func TestBasicSign(t *testing.T) {
	kr := NewKeyring()
	k1, err := kr.GenerateSigningKey()
	if err != nil {
		t.Fatal(err)
	}
	msg := randomMsg(t, 1024)
	sig, err := saltpack.SignArmor62(msg, k1, "")
	if err != nil {
		t.Fatal(err)
	}
	pk, msg2, _, err := saltpack.Dearmor62Verify(sig, kr)
	if err != nil {
		t.Fatal(err)
	}
	if !bytes.Equal(msg, msg2) {
		t.Fatal("msg payload mismatch")
	}
	if !saltpack.PublicKeyEqual(k1.GetPublicKey(), pk) {
		t.Fatal("public signing key wasn't right")
	}
}