gnupg - Go - Golang openpg - Create Key pair and create signature -


i'm working on openpgp in combination golang. use following code generate new keypair , create self-signature on resulting public key:

package main  import (     "bytes"     "crypto"     "time"     "golang.org/x/crypto/openpgp"     "golang.org/x/crypto/openpgp/armor"     "golang.org/x/crypto/openpgp/packet"     "fmt" )  //create asscii armor openpgp.entity func 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", "itis@itis3.com", nil)     if err != nil {         fmt.println("error")     }      usridstring := ""     _, uids := range entity.identities {         usridstring = uids.name      }      var prikey = entity.privatekey     var sig = new(packet.signature)         //prepare sign our configs/////is 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")     }     err = sig.signuserid(usridstring, entity.primarykey, entity.privatekey, nil)     if err != nil {         fmt.println("error")     }      entity.signidentity(usridstring, entity, nil)      var copy = entity     var asciisignedkey = pubenttoasciiarmor(copy)     fmt.println(asciisignedkey) } 

1.) when serialize public key (to armored version of it), following error message:

serializing pubkey openpgp: invalid argument: signature: need call sign, signuserid or signkey before serialize

i thought used every possible way create signature on key?

2.) still receive output problem 1, when upload key keyserver, available information incomplete. key-id , creation date listed. additional information like, self-signature, user-id-string , on missing (example: https://pgp.mit.edu/pks/lookup?search=0xbe6ee21e94a73ba5&op=index). went wrong? related error 1?

ps: new golang, started today.

maybe want. disclaimer: not expert in openpgp; don't know whether correct or not. work gpg --import.

package main  import (         "fmt"         "os"          "golang.org/x/crypto/openpgp"         "golang.org/x/crypto/openpgp/armor" )  func main() {         var e *openpgp.entity         e, err := openpgp.newentity("itis", "test", "itis@itis3.com", nil)         if err != nil {                 fmt.println(err)                 return         }          // add more identities here if wish          // sign identities         _, id := range e.identities {                 err := id.selfsignature.signuserid(id.userid.id, e.primarykey, e.privatekey, nil)                 if err != nil {                         fmt.println(err)                         return                 }         }          w, err := armor.encode(os.stdout, openpgp.publickeytype, nil)         if err != nil {                 fmt.println(err)                 return         }         defer w.close()          e.serialize(w) } 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -