public and private keys generated by Fabric case
The
Fabric case generates public and private key pairs for nodes such as Peer, User, Admin, etc. Public and private keys are shown in the figure below.
example of signing and validating with public and private key pairs
Example code for signing and validating a message with the above public and private key pairs is shown below.package main
import (
"crypto/ecdsa"
"crypto/rand"
"crypto/sha256"
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
)
func main() {
msg := "hello, world"
hash := sha256.Sum256([]byte(msg))
msg2 := "Hello, world"
hash2 := sha256.Sum256([]byte(msg2))
privBytes, _ := ioutil.ReadFile("./priv_sk")
blkPriv, _ := pem.Decode(privBytes)
fmt.Println("priv_sk type:", blkPriv.Type)
key, _ := x509.ParsePKCS8PrivateKey(blkPriv.Bytes)
ecdsaKey := key.(*ecdsa.PrivateKey)
r, s, _ := ecdsa.Sign(rand.Reader, ecdsaKey, hash[:])
certBytes, _ := ioutil.ReadFile("./cert.pem")
blkCert, _ := pem.Decode(certBytes)
fmt.Println("cert.pem type:", blkCert.Type)
cert, _ := x509.ParseCertificate(blkCert.Bytes)
pubkey := cert.PublicKey.(*ecdsa.PublicKey)
ok := ecdsa.Verify(pubkey, hash[:], r, s)
fmt.Println("verify hash(shoule be true):", ok)
ok = ecdsa.Verify(pubkey, hash2[:], r, s)
fmt.Println("verify hash2(shoule be false):", ok)
}
compiles and runs as shown below.
Read More:
- A simple method of generating secret key by GIT and configuring SSH public key
- Wechat payment API V3 payment notice asynchronous signature verification failed
- MySql 8.x java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
- Git still needs to enter the user name and password after configuring the public key
- Error: permission denied (public key, GSSAPI keyex, GSSAPI with MIC, password)
- Solve host key verification failed [valid]
- Host key verification failed. fatal: Could not read from remote repository.
- Macro generated_ UCLASS_ Body () and generated_ Analysis of body ()
- Syntax error or access violation: 1071 specified key was too long; max key length is 767 bytes
- Matlab: Three forms of random number generated (Rand, Randi and Randn)
- Fabric appears when trying to use application call: Unknown: access denied: Channel [mychannel] creator org [org1msp]
- Flume profile case (Port listening)
- Forsage fossage system development (build case)
- error starting container: API error (404): network fabric_test not found“
- Implementation of Python switch / case statements
- Python switch / case statement implementation method
- The local program cannot access the test environment redis cluster through public IP_ compromise
- Mybatis automatically generated SQL error
- C++ error: jump to case label crosses initialization
- C++ [Error] jump to case label [-fpermissive]