Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated signing message section of README.md #263

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,33 @@ const privkey = `-----BEGIN PGP PRIVATE KEY BLOCK-----
-----END PGP PRIVATE KEY BLOCK-----` // Encrypted private key
const passphrase = []byte("LongSecret") // Private key passphrase

var message = crypto.NewPlaintextMessage("Verified message")
var message = crypto.NewPlainMessageFromString("Verified message")

privateKeyObj, err := crypto.NewKeyFromArmored(privkey)
unlockedKeyObj = privateKeyObj.Unlock(passphrase)
signingKeyRing, err := crypto.NewKeyRing(unlockedKeyObj)
privateKeyObj, err := crypto.NewKeyFromArmoredReader(f)
if err != nil {
log.Fatalf("failed to create private key object, %s", err)
}

pgpSignature, err := signingKeyRing.SignDetached(message, trimNewlines)
unlockedKeyObj, err := privateKeyObj.Unlock(passphrase)
if err != nil {
log.Fatalf("failed to unlock key %s", err)
}

signingKeyring, err := crypto.NewKeyRing(unlockedKeyObj)
if err != nil {
log.Fatalf("failed to create new keyring %s", err)
}

pgpSignature, err := signingKeyring.SignDetached(message)
if err != nil {
log.Fatalf("failed to sign message %s", err)
}

// The armored signature is in pgpSignature.GetArmored()
fmt.Println(pgpSignature.GetArmored())

// The signed text is in message.GetString()
fmt.Println(message.GetString())
```

To verify a signature either private or public keyring can be provided.
Expand Down