private static string GetValue(string attributeName, IAttributes attributes, bool isAddAndNotPostBack, string defaultValue) { var value = attributes.Get(attributeName); if (isAddAndNotPostBack && value == null) { value = defaultValue; } return(value.ToString()); }
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); } }