Search code examples
hyperledger-composer

Error: Failed to import identity. Error: privateKey not specified or not a string


I created my network with a admin card which I request before, but when I want to import this card to card store it Error:

Failed to import identity. Error: privateKey not specified or not a string

and import failure.

My operation is: 1. create PeerAdmin card:

composer card create -p ./santai/byfn-network-test.json -u PeerAdmin -c ./santai/Admin@santai.chembeango.com-cert.pem -k ./santai/689f471246b0e180384660285aff48dcc5e12b9fd6bed4e5a47cce7ce367310f_sk -r PeerAdmin -r ChannelAdmin -f PeerAdmin@chembeango-network-test.card

  1. import the PeerAdmin card into card store:

    composer card import -f PeerAdmin@chembeango-network-test.card --card PeerAdmin@chembeango-network-test

  2. identity request:

composer identity request -c PeerAdmin@chembeango-network-test -u test -s t789456 -d test

  1. start network

composer network start -c PeerAdmin@chembeango-network-test -n chembeango-test-network -V 0.0.1 -o endorsementPolicyFile=./endorsement-policy.json -A test -C test/test-pub.pem

  1. import admin card

    composer card import -f test@chembeango-test-network.card

I checked My priv pem, it is:

-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgGPwysYDw6+TLcgiv
QOHt7vhm3j5A9muqwmIKutoxdhGhRANCAASDNP95hp3tpLda5qGD2LTSfpjD4x4t
mqYlov5eIQhG1Nq7BXdn0fJYtpPB5T5odaoheUU0xDcC4BXAmqb9LYif
-----END PRIVATE KEY-----

I have mv my card to a zip file, and unzipped it,the structure is:

 extracting: connection.json
 extracting: metadata.json
   creating: credentials/
 extracting: credentials/certificate

I didn't find the priv key, is this the problem?


Solution

  • You are correct, the card that is automatically created for you does not contain the private key!

    You need to delete that automatically generated card and create a new one yourself containing the certificate and key. So you will need 2 commands similar to these - I'm suggesting using 'test2' so there is no confusion:

    composer card create -p ./santai/byfn-network-test.json -u test -c test/test-pub.pem -k test/test-priv.pem -f test2.card -n chembeango-test-network

    composer card import -f test2.card -c test2@chembeango

    (The automatically generated cards work OK in single org environments if you specify the username and secret on the composer network start command, but if you request the identity first and then use the certificate on the start command the resulting card does not contain the private key)