Add decryptMime and refactor package structure

This commit is contained in:
Kay Lukas 2018-09-11 11:09:28 +02:00
parent 07b3a2c739
commit 97e70855b8
27 changed files with 516 additions and 486 deletions

View file

@ -1,32 +0,0 @@
package pmcrypto
import (
"bytes"
"encoding/hex"
"errors"
"golang.org/x/crypto/openpgp"
)
// GetFingerprint get a armored public key fingerprint
func GetFingerprint(publicKey string) (string, error) {
rawPubKey, err := UnArmor(publicKey)
if err != nil {
return "", err
}
return GetFingerprintBinKey(rawPubKey)
}
// GetFingerprintBinKey get a unarmored public key fingerprint
func GetFingerprintBinKey(publicKey []byte) (string, error) {
pubKeyReader := bytes.NewReader(publicKey)
pubKeyEntries, err := openpgp.ReadKeyRing(pubKeyReader)
if err != nil {
return "", err
}
for _, e := range pubKeyEntries {
fp := e.PrimaryKey.Fingerprint
return hex.EncodeToString(fp[:]), nil
}
return "", errors.New("Can't find public key")
}