started to implement the key generator

This commit is contained in:
didier.amyot committed 2014-07-29 11:45:23 -04:00
1 parent ad4510711e
commit 776c73b91c
7 files changed
+233 -2

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
package main
import (
"crypto/rand"
"crypto/rsa"
"errors"
)
type KeyGenerator struct {
publicKey *PublicKey
privateKey *PrivateKey
}
func (this *KeyGenerator) createRSAKey(size int) error {
rsaPrivateKey, err := rsa.GenerateKey(rand.Reader, size)
if err != nil {
return errors.New("cannot generate the rsa public/private key pair\n" + err.Error())
}
if this.privateKey, err = GetDefaultRSAPrivateKey(rsaPrivateKey); err != nil {
return errors.New("cannot generate the rsa public/private key pair\n" + err.Error())
}
this.publicKey = GetDefaultRSAPublicKey(&rsaPrivateKey.PublicKey)
return nil
}
func (this *KeyGenerator) CreateNewKey(size int, password string) error {
if err := this.createRSAKey(size); err != nil {
return err
}
return nil
}