go-pgp/pgp/sign_test.go

39 lines
865 B
Go
Raw Permalink Normal View History

2024-07-25 16:25:01 +02:00
package pgp
import (
"fmt"
"testing"
"golang.org/x/crypto/openpgp"
)
func TestSignature(t *testing.T) {
fmt.Println("Signature test: START")
entity, err := GetEntity([]byte(testPublicKey), []byte(testPrivateKey))
if err != nil {
t.Error(err)
}
fmt.Println("Created private key entity.")
var signature []byte
signature, err = Sign(entity, []byte(testMessage))
if err != nil {
t.Error(err)
}
fmt.Println("Created signature of test message with private key entity.")
var publicKeyEntity *openpgp.Entity
publicKeyEntity, err = GetEntity([]byte(testPublicKey), []byte{})
if err != nil {
t.Error(err)
}
fmt.Println("Created public key entity.")
err = Verify(publicKeyEntity, []byte(testMessage), signature)
if err != nil {
t.Error(err)
}
fmt.Println("Signature verified using public key entity.")
fmt.Println("Signature test: END")
}