本文整理汇总了Golang中github.com/agl/ed25519.GenerateKey函数的典型用法代码示例。如果您正苦于以下问题:Golang GenerateKey函数的具体用法?Golang GenerateKey怎么用?Golang GenerateKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GenerateKey函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestSignProof
func TestSignProof(t *testing.T) {
pubkeyRec, privKeyRec, _ := ed25519.GenerateKey(rand.Reader)
pubkeySend, privkeySend, _ := ed25519.GenerateKey(rand.Reader)
now := time.Now().UnixNano()
proof := SignProofToken(now, pubkeyRec, pubkeySend, privkeySend)
ok, nowDec, senderPub := VerifyProofToken(proof, pubkeyRec)
if !ok {
t.Error("Siganture did not verify")
}
if *senderPub != *pubkeySend {
t.Error("Sender Pubkey decode failed")
}
if now != nowDec {
t.Error("Time decode failed")
}
ok, signedProofToken := CounterSignToken(proof, pubkeyRec, privKeyRec)
if !ok {
t.Error("CounterSignToken did not verify")
}
ok, nowDec2 := VerifyCounterSig(signedProofToken, pubkeySend)
if !ok {
t.Error("VerifyCounterSig did not verify")
}
if now != nowDec2 {
t.Error("Time decode failed")
}
}
开发者ID:carriercomm,项目名称:repbin,代码行数:27,代码来源:prooftoken_test.go示例2: TestGenerateIDKeys
func TestGenerateIDKeys(t *testing.T) {
var err error
clientPK, clientSK, err = ed25519.GenerateKey(rand.Reader)
if err != nil {
t.Fatalf("%v", err)
}
serverPK, serverSK, err = ed25519.GenerateKey(rand.Reader)
if err != nil {
t.Fatalf("%v", err)
}
}
开发者ID:jmptrader,项目名称:go-schannel,代码行数:12,代码来源:schannel_test.go示例3: GenerateKeys
func GenerateKeys(random io.Reader) (*[64]byte, *[32]byte) {
pub, priv, err := ed25519.GenerateKey(random)
if err != nil {
lg.Fatal(err)
}
return priv, pub
}
开发者ID:gitter-badger,项目名称:alkasir,代码行数:7,代码来源:upgradebin.go示例4: getSigningKey
func getSigningKey() (*[ed25519.PublicKeySize]byte, *[ed25519.PrivateKeySize]byte) {
pub, priv, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
log.Fatal(err)
}
return pub, priv
}
开发者ID:rakoo,项目名称:challengeauth,代码行数:7,代码来源:main.go示例5: init
func init() {
var err error
testKeyPub, testKeyPriv, err = ed25519.GenerateKey(rand.Reader)
if err != nil {
panic(err)
}
}
开发者ID:read-later,项目名称:bazil,代码行数:7,代码来源:client_test.go示例6: TestCheckToken
func TestCheckToken(t *testing.T) {
now := uint64(times.Now()) / SkewWindow
pubkey, privkey, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
t.Fatalf("Key generation failed: %s", err)
}
authtoken := CreateToken(pubkey, privkey, 1)
pubkey2, ltime, lcounter, err := authtoken.CheckToken()
if err != nil {
t.Errorf("Token verification failed: %s", err)
}
if *pubkey2 != *pubkey {
t.Errorf("Token decode failed, pubkey does not match: %x!=%x", *pubkey2, *pubkey)
}
if lcounter != 1 {
t.Errorf("Token decode failed. Counter %d!=1", lcounter)
}
if uint64(math.Abs(float64(ltime-now))) > 1 {
t.Errorf("Token decode failed. Time: %d!=%d", now, ltime)
}
authtoken[0] = 0x00
_, _, _, err = authtoken.CheckToken()
if err == nil {
t.Error("Token verification MUST fail")
}
}
开发者ID:JonathanLogan,项目名称:mute,代码行数:26,代码来源:walletauth_test.go示例7: TestConv
func TestConv(t *testing.T) {
pubkey, privkey, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
t.Fatalf("Keygen failed: %s", err)
}
sm := make(StringMap)
sm["alpha"] = "first"
sm["beta"] = "second"
sm["gamma"] = "third"
sm["delta"] = "fourth"
ss := sm.Sort()
if ss[0].K != "alpha" || ss[0].V != "first" {
t.Error("Bad first")
}
if ss[3].K != "gamma" || ss[3].V != "third" {
t.Error("Bad last")
}
sig := ss.Sign(10, privkey)
if !ss.Verify(10, pubkey[:], sig) {
t.Error("Signature verify failed")
}
if ss.Verify(11, pubkey[:], sig) {
t.Error("Signature verification MUST fail on bad date")
}
sig[3] = ^sig[3]
if ss.Verify(10, pubkey[:], sig) {
t.Error("Signature verification MUST fail on bad signature")
}
}
开发者ID:JonathanLogan,项目名称:mute,代码行数:29,代码来源:map_test.go示例8: main
func main() {
user = new(common.User)
game = new(common.Game)
var err error
pubkey, privkey, err = ed25519.GenerateKey(rand.Reader)
if err != nil {
panic(err)
}
socket, err := utp.Dial("localhost:5428")
if err != nil {
panic(err)
}
if !handshake(socket) {
panic("Handshake to server failed!")
}
rl, err = readline.NewEx(&readline.Config{
Prompt: "> ",
// HistoryFile: "./readline.history",
InterruptPrompt: "Ctrl-C received, exiting ...",
EOFPrompt: "\n",
AutoComplete: completer,
})
stderr = rl.Stderr()
go downstream()
upstream()
}
开发者ID:jackyyf,项目名称:isreversi,代码行数:26,代码来源:client.go示例9: main
func main() {
showHelp := flag.Bool("h", false, "display a short usage message and exit")
flag.Parse()
if *showHelp {
usage()
os.Exit(0)
}
if flag.NArg() == 0 {
usage()
os.Exit(1)
}
for _, baseName := range flag.Args() {
pubFileName := fmt.Sprintf("%s.pub", baseName)
privFileName := fmt.Sprintf("%s.key", baseName)
pub, priv, err := ed25519.GenerateKey(rand.Reader)
die.If(err)
err = ioutil.WriteFile(pubFileName, pub[:], 0644)
die.If(err)
err = ioutil.WriteFile(privFileName, priv[:], 0600)
die.If(err)
}
}
开发者ID:jmptrader,项目名称:go-schannel,代码行数:28,代码来源:keygen.go示例10: Ed25519Generate
// Ed25519Generate generates a new Ed25519 key pair.
func Ed25519Generate(rand io.Reader) (*Ed25519Key, error) {
publicKey, privateKey, err := ed25519.GenerateKey(rand)
if err != nil {
return nil, err
}
return &Ed25519Key{publicKey, privateKey}, nil
}
开发者ID:JonathanLogan,项目名称:mute,代码行数:8,代码来源:ed25519.go示例11: New
// New returns a MessageServer.
func New(driver, url, path string, pubKey, privKey []byte) (*MessageServer, error) {
var err error
ms := new(MessageServer)
ms.DB = messagestore.New(driver, url, path, Workers)
if err != nil {
return nil, err
}
ms.path = path
ms.PeerFile = path + "peers.config"
ms.AddToPeer = DefaultAddToPeer
ms.MaxTimeSkew = DefaultMaxTimeSkew
ms.MinPostSize = MinPostSize
ms.MaxPostSize = MaxPostSize
ms.MinHashCashBits = MinHashCashBits
ms.MaxSleep = DefaultMaxSleep
ms.MaxIndexGlobal = DefaultIndexGlobal
ms.MaxIndexKey = DefaultIndexKey
ms.TimeGrace = DefaultTimeGrace
ms.MaxAuthTokenAge = DefaultAuthTokenAge
ms.NotifyDuration = DefaultNotifyDuration
ms.FetchDuration = DefaultFetchDuration
ms.FetchMax = DefaultFetchMax
ms.ExpireDuration = DefaultExpireDuration
ms.ExpireFSDuration = DefaultExpireFSDuration
ms.StepLimit = DefaultStepLimit
ms.ListenPort = DefaultListenPort
ms.MinStoreTime = DefaultMinStoreTime
ms.MaxStoreTime = DefaultMaxStoreTime
ms.MaxAgeSigners = DefaultMaxAgeSigners
ms.MaxAgeRecipients = DefaultMaxAgeRecipients
messagestore.MaxAgeRecipients = DefaultMaxAgeRecipients
messagestore.MaxAgeSigners = DefaultMaxAgeSigners
ms.EnablePeerHandler = true
ms.authPrivKey, err = message.GenLongTermKey(true, false)
if err != nil {
return nil, err
}
ms.AuthPubKey = message.GenPubKey(ms.authPrivKey)
if pubKey != nil && privKey != nil {
ms.TokenPubKey = new([ed25519.PublicKeySize]byte)
ms.TokenPrivKey = new([ed25519.PrivateKeySize]byte)
copy(ms.TokenPubKey[:], pubKey)
copy(ms.TokenPrivKey[:], privKey)
} else {
ms.TokenPubKey, ms.TokenPrivKey, err = ed25519.GenerateKey(rand.Reader)
log.Printf("Peer authentication public key: %s\n", utils.B58encode(ms.TokenPubKey[:]))
log.Printf("Peer authentication private key: %s\n", utils.B58encode(ms.TokenPrivKey[:]))
if err != nil {
return nil, err
}
}
ms.InfoStruct = new(ServerInfo)
ms.InfoStruct.MinHashCashBits = ms.MinHashCashBits
ms.InfoStruct.MinPostSize = ms.MinPostSize
ms.InfoStruct.MaxPostSize = ms.MaxPostSize
ms.InfoStruct.AuthPubKey = utils.B58encode(ms.AuthPubKey[:])
return ms, nil
}
开发者ID:RoPe93,项目名称:repbin,代码行数:60,代码来源:server.go示例12: GenerateSigningKeyPair
// GenerateSigningKeyPair attempts to generate a signature key-pair.
func GenerateSigningKeyPair() (sk, vk []byte, err error) {
pub, priv, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
return nil, nil, errors.New("failed to generate secret signing key: " + err.Error())
}
return priv[:], pub[:], nil
}
开发者ID:pylls,项目名称:balloon,代码行数:9,代码来源:sign.go示例13: GenerateSigningKey
// GenerateSigningKey generates a signing key and import it into the keyring.
func (k *Keyring) GenerateSigningKey() (*SigningSecretKey, error) {
pub, sec, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
return nil, err
}
ret := NewSigningSecretKey(pub, sec)
return &ret, nil
}
开发者ID:Varjelus,项目名称:keybase-client,代码行数:9,代码来源:key.go示例14: keys
func (kp *Full) keys() (*[32]byte, *[64]byte) {
reader := bytes.NewReader(kp.rawSeed())
pub, priv, err := ed25519.GenerateKey(reader)
if err != nil {
panic(err)
}
return pub, priv
}
开发者ID:stellar,项目名称:bridge-server,代码行数:8,代码来源:full.go示例15: GenerateSignatureKeys
// GenerateKeyPair creates a public-secret keypair that can be used to sign and
// verify messages.
func GenerateSignatureKeys() (sk SecretKey, pk PublicKey, err error) {
pkPointer, skPointer, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
return
}
sk = *skPointer
pk = *pkPointer
return
}
开发者ID:mm3,项目名称:Sia,代码行数:11,代码来源:signatures.go本文标签属性:
示例:示例是什么意思
代码:代码是什么
Golang:Golang
GenerateKey:GenerateKey