예제 #1
0
        public async Task <ISecretKey> Generate(IMasterKey masterKey, IPublicKey publicKey, IAttributes attributes)
        {
            try
            {
                var masterKeyFile = await LocalHost.WriteFileAsync(masterKey.Value);

                var publicKeyFile = await LocalHost.WriteFileAsync(publicKey.Value);

                var privateKeyFile = LocalHost.GetRandomFilename();

                await LocalHost.RunProcessAsync("cpabe-keygen", $"-o {privateKeyFile} {publicKeyFile} {masterKeyFile} {attributes.Get()}");

                var privateKeyBytes = await LocalHost.ReadFileAsync(privateKeyFile);

                var privateKey = new MockSecretKey()
                {
                    Value = privateKeyBytes
                };

                File.Delete(masterKeyFile);
                File.Delete(publicKeyFile);
                File.Delete(privateKeyFile);

                return(privateKey);
            }
            catch (Exception exception)
            {
                throw new ABESchemeException($"Error has occured during secret key generation: {attributes.Get()}", exception);
            }
        }
예제 #2
0
        private async Task CheckKeys()
        {
            if (publicKey == null)
            {
                var keys = await cpabeCenter.Setup();

                publicKey = keys.PublicKey;
                masterKey = keys.MasterKey;
            }
        }