public async static Task <EncryptionCredentials> Get() { var keysService = new KeysClient(AppToken); var privateKeysService = new KeyringClient(AppToken); privateKeysService.Connection.SetCredentials(new Credentials(EmailId, ContainerPassword)); var key = await keysService.PublicKeys.Search(EmailId); var privatek = await privateKeysService.PrivateKeys.Get(key.PublicKeyId); return(new EncryptionCredentials(key.Key, privatek.Key, Encoding.UTF8.GetBytes(key.PublicKeyId.ToString()))); }
public async static Task CreateKeyPair() { var keysService = new KeysClient(AppToken); var privateKeysService = new KeyringClient(AppToken); //var key = await keysService.PublicKeys.Search(EmailId); byte[] publicKey; byte[] privateKey; // Step 1. Generate Public/Private key pair. using (var keyPair = new VirgilKeyPair()) { publicKey = keyPair.PublicKey(); privateKey = keyPair.PrivateKey(); } Console.WriteLine("Generated Public/Private keys\n"); Console.WriteLine(Encoding.UTF8.GetString(publicKey)); Console.WriteLine(Encoding.UTF8.GetString(privateKey)); // Step 2. Register Public Key on Keys Service. var userData = new UserData { Class = UserDataClass.UserId, Type = UserDataType.EmailId, Value = EmailId }; var vPublicKey = await keysService.PublicKeys.Create(publicKey, privateKey, userData); // Step 3. Confirm UDID (User data identity) with code recived on email box. Console.WriteLine("Enter Confirmation Code:"); var confirmCode = Console.ReadLine(); await keysService.UserData.Confirm(vPublicKey.UserData.First().UserDataId, confirmCode, vPublicKey.PublicKeyId, privateKey); Console.WriteLine("Public Key has been successfully published." + vPublicKey.PublicKeyId); // Step 4. Store Private Key on Private Keys Service. await privateKeysService.Container.Initialize(ContainerType.Easy, vPublicKey.PublicKeyId, privateKey, ContainerPassword); privateKeysService.Connection.SetCredentials(new Credentials(EmailId, ContainerPassword)); await privateKeysService.PrivateKeys.Add(vPublicKey.PublicKeyId, privateKey); }