예제 #1
0
        /**
         * Get the user with a given name
         *
         * @param name
         * @param org
         * @param mspId
         * @param privateKeyFile
         * @param certificateFile
         * @return user
         * @throws IOException
         * @throws NoSuchAlgorithmException
         * @throws NoSuchProviderException
         * @throws InvalidKeySpecException
         */
        public SampleUser GetMember(string name, string org, string mspId, string privateKeyFile, string certificateFile)
        {
            try
            {
                // Try to get the SampleUser state from the cache
                SampleUser sampleUser = members.GetOrNull(SampleUser.ToKeyValStoreName(name, org));
                if (null != sampleUser)
                {
                    return(sampleUser);
                }

                // Create the SampleUser and try to restore it's state from the key value store (if found).
                sampleUser       = new SampleUser(name, org, this, cryptoSuite);
                sampleUser.MspId = mspId;
                string certificate = File.ReadAllText(certificateFile, Encoding.UTF8);

                KeyPair pair = KeyPair.Create(File.ReadAllText(privateKeyFile));

                sampleUser.Enrollment = new SampleStoreEnrollement(pair.Pem, certificate);

                sampleUser.SaveState();

                return(sampleUser);
            }
            catch (IOException e)
            {
                logger.ErrorException(e.Message, e);
                throw;
            }
            catch (System.Exception e)
            {
                logger.ErrorException(e.Message, e);
                throw;
            }
        }
예제 #2
0
        /**
         * Check if store has user.
         *
         * @param name
         * @param org
         * @return true if the user exists.
         */
        public bool HasMember(string name, string org)
        {
            // Try to get the SampleUser state from the cache

            if (members.ContainsKey(SampleUser.ToKeyValStoreName(name, org)))
            {
                return(true);
            }

            return(SampleUser.IsStored(name, org, this));
        }
예제 #3
0
        /**
         * Get the user with a given name
         *
         * @param name
         * @param org
         * @return user
         */
        public SampleUser GetMember(string name, string org)
        {
            // Try to get the SampleUser state from the cache

            SampleUser sampleUser = members.GetOrNull(SampleUser.ToKeyValStoreName(name, org));

            if (null != sampleUser)
            {
                return(sampleUser);
            }

            // Create the SampleUser and try to restore it's state from the key value store (if found).
            sampleUser = new SampleUser(name, org, this, cryptoSuite);

            return(sampleUser);
        }