Add ToPublic method to get a public key object from a private key (#65)
This commit is contained in:
parent
48f05401ce
commit
979fdb3f4b
3 changed files with 36 additions and 0 deletions
|
|
@ -359,6 +359,21 @@ func (key *Key) GetEntity() *openpgp.Entity {
|
|||
return key.entity
|
||||
}
|
||||
|
||||
// ToPublic returns the corresponding public key of the given private key.
|
||||
func (key *Key) ToPublic() (publicKey *Key, err error) {
|
||||
if !key.IsPrivate() {
|
||||
return nil, errors.New("gopenpgp: key is already public")
|
||||
}
|
||||
|
||||
publicKey, err = key.Copy()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
publicKey.ClearPrivateParams()
|
||||
return
|
||||
}
|
||||
|
||||
// --- Internal methods
|
||||
|
||||
// getSHA256FingerprintBytes computes the SHA256 fingerprint of a public key
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue