我目前正在結合 golang 開發 openpgp。我使用以下代碼生成新的密鑰對并在生成的公鑰上創建自簽名:package mainimport ( "bytes" "crypto" "time" "golang.org/x/crypto/openpgp" "golang.org/x/crypto/openpgp/armor" "golang.org/x/crypto/openpgp/packet" "fmt")//Create ASscii Armor from openpgp.Entityfunc PubEntToAsciiArmor(pubEnt *openpgp.Entity) (asciiEntity string) { gotWriter := bytes.NewBuffer(nil) wr, errEncode := armor.Encode(gotWriter, openpgp.PublicKeyType, nil) if errEncode != nil { fmt.Println("Encoding Armor ", errEncode.Error()) return } errSerial := pubEnt.Serialize(wr) if errSerial != nil { fmt.Println("Serializing PubKey ", errSerial.Error()) } errClosing := wr.Close() if errClosing != nil { fmt.Println("Closing writer ", errClosing.Error()) } asciiEntity = gotWriter.String() return}func main() { var entity *openpgp.Entity entity, err := openpgp.NewEntity("itis", "test", "[email protected]", nil) if err != nil { fmt.Println("ERROR") } usrIdstring := "" for _, uIds := range entity.Identities { usrIdstring = uIds.Name } var priKey = entity.PrivateKey var sig = new(packet.Signature) //Prepare sign with our configs/////IS IT A MUST ?? sig.Hash = crypto.SHA1 sig.PubKeyAlgo = priKey.PubKeyAlgo sig.CreationTime = time.Now() dur := new(uint32) *dur = uint32(365 * 24 * 60 * 60) sig.SigLifetimeSecs = dur //a year issuerUint := new(uint64) *issuerUint = priKey.KeyId sig.IssuerKeyId = issuerUint sig.SigType = packet.SigTypeGenericCert err = sig.SignKey(entity.PrimaryKey, entity.PrivateKey, nil) if err != nil { fmt.Println("ERROR") }1.) 當我序列化公鑰(以獲得它的裝甲版本)時,我收到以下錯誤消息:序列化 PubKey openpgp:無效參數:簽名:需要在序列化之前調用 Sign、SignUserId 或 SignKey我以為我只是使用了所有可能的方法在該密鑰上創建簽名?2.) 我仍然收到問題 1 的輸出,當我將密鑰上傳到密鑰服務器時,可用信息不完整。僅列出密鑰 ID 和創建日期。缺少所有其他信息,例如自簽名、用戶 ID 字符串等(例如:https : //pgp.mit.edu/pks/lookup?search=0xbe6ee21e94a73ba5&op=index)。什么地方出了錯?它與錯誤1有關嗎?PS:我剛接觸golang,今天開始。
- 3 回答
- 0 關注
- 313 瀏覽
添加回答
舉報
0/150
提交
取消