Skip to content

Commit

Permalink
Create diam.go
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 7, 2024
1 parent 8907e17 commit 471ffe6
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions identity/diam/diam.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package diam

import (
"crypto/ecdsa"
"crypto/rand"
"crypto/x509"
"encoding/pem"
"fmt"
)

type Identity struct {
privateKey *ecdsa.PrivateKey
publicKey *ecdsa.PublicKey
}

func NewIdentity() (*Identity, error) {
privateKey, err := ecdsa.GenerateKey(rand.Reader, 256)
if err != nil {
return nil, err
}
publicKey := privateKey.Public()

return &Identity{privateKey, publicKey}, nil
}

func (i *Identity) Sign(data []byte) ([]byte, error) {
hash := sha256.Sum256(data)
signature, err := i.privateKey.Sign(rand.Reader, hash[:], nil)
if err != nil {
return nil, err
}
return signature, nil
}

0 comments on commit 471ffe6

Please sign in to comment.