Initial commit
This commit is contained in:
34
keymgmt/keymgmt.go
Normal file
34
keymgmt/keymgmt.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package keymgmt
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/rsa"
|
||||
"encoding/base64"
|
||||
"golang.org/x/crypto/sha3"
|
||||
"log"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
type Address struct {
|
||||
pubkey int
|
||||
privkey *rsa.PrivateKey
|
||||
mod *big.Int
|
||||
}
|
||||
|
||||
func GenerateAddress() *Address {
|
||||
key, err := rsa.GenerateKey(rand.Reader, 1024)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
newAddress := Address{pubkey: key.E, privkey: key, mod: key.N}
|
||||
return &newAddress
|
||||
}
|
||||
|
||||
func (a Address) GetAddress() string {
|
||||
hasher := sha3.New224()
|
||||
hash := hasher.Sum(a.privkey.N.Bytes())
|
||||
b64 := "!MBPA#" + base64.StdEncoding.EncodeToString(hash)[:64]
|
||||
|
||||
return b64
|
||||
}
|
||||
Reference in New Issue
Block a user