35 lines
595 B
Go
35 lines
595 B
Go
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, 512)
|
|
|
|
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
|
|
}
|