Пример #1
0
        /// <summary>
        /// Decrypts and verifies the data.
        /// </summary>
        /// <param name="cipherbuffer">The data to be decrypted.</param>
        /// <param name="card">The signer's <see cref="VirgilCard"/>.</param>
        /// <returns>The decrypted data, which is the original plain text before encryption.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public VirgilBuffer DecryptThenVerify(VirgilBuffer cipherbuffer, VirgilCard card)
        {
            var plaitext = this.context.Crypto
                           .DecryptThenVerify(cipherbuffer.GetBytes(), this.privateKey, card.PublicKey);

            return(new VirgilBuffer(plaitext));
        }
Пример #2
0
        /// <summary>
        /// Revokes a <see cref="VirgilCard"/> from Virgil Services.
        /// </summary>
        /// <param name="card">The card to be revoked.</param>
        public async Task RevokeAsync(VirgilCard card)
        {
            if ((this.context == null) || (this.context.Credentials == null) ||
                (this.context.Credentials.GetAppId() == null) ||
                (this.context.Credentials.GetAppKey(context.Crypto) == null))
            {
                throw new AppCredentialsException();
            }
            var revokeRequest = new RevokeCardRequest(card.Id, RevocationReason.Unspecified);

            var appId  = this.context.Credentials.GetAppId();
            var appKey = this.context.Credentials.GetAppKey(this.context.Crypto);


            var fingerprint = this.context.Crypto.CalculateFingerprint(revokeRequest.Snapshot);
            var signature   = this.context.Crypto.Sign(fingerprint.GetValue(), appKey);

            revokeRequest.AppendSignature(appId, signature);

            /* to_ask
             * var requestSigner = new RequestSigner(this.context.Crypto);
             * requestSigner.AuthoritySign(revokeRequest, appId, appKey); */

            await this.context.Client.RevokeCardAsync(revokeRequest);
        }
Пример #3
0
        /// <summary>
        /// Gets a <see cref="VirgilCard"/> from Virgil Security services by specified Card ID.
        /// </summary>
        /// <param name="cardId">is a unique string that identifies the Card
        /// within Virgil Security services.</param>
        /// <returns>an instance of <see cref="VirgilCard"/> class.</returns>
        public async Task <VirgilCard> GetAsync(string cardId)
        {
            var cardModel = await this.context.Client.GetCardAsync(cardId).ConfigureAwait(false);

            var card = new VirgilCard(this.context, cardModel);

            return(card);
        }
Пример #4
0
        /// <summary>
        /// Encrypts the specified text for <paramref name="recipient"/> Card.
        /// </summary>
        /// <param name="recipient">The list of <see cref="VirgilCard"/> recipients.</param>
        /// <param name="plaintext">The plaintext to be encrypted.</param>
        /// <returns>A new <see cref="VirgilBuffer"/> with encrypted data.</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static VirgilBuffer Encrypt(this VirgilCard recipient, string plaintext)
        {
            if (string.IsNullOrWhiteSpace(plaintext))
            {
                throw new ArgumentException(Localization.ExceptionArgumentIsNullOrWhitespace, nameof(plaintext));
            }

            return(recipient.Encrypt(VirgilBuffer.From(plaintext)));
        }
Пример #5
0
        /// <summary>
        /// Revokes a global <see cref="VirgilCard"/> from Virgil Security services.
        /// </summary>
        /// <param name="card">The Card to be revoked.</param>
        /// <param name="key">The Key associated with the revoking Card.</param>
        /// <param name="identityToken">The identity token.</param>
        public async Task RevokeGlobalAsync(VirgilCard card, VirgilKey key, IdentityValidationToken identityToken)
        {
            var revokeRequest = new RevokeGlobalCardRequest(card.Id, RevocationReason.Unspecified, identityToken.Value);

            var fingerprint = this.context.Crypto.CalculateFingerprint(revokeRequest.Snapshot);
            var signature   = key.Sign(fingerprint.GetValue());

            revokeRequest.AppendSignature(card.Id, signature.GetBytes());

            await this.context.Client.RevokeGlobalCardAsync(revokeRequest);
        }
Пример #6
0
        /// <summary>
        /// Revokes a <see cref="VirgilCard"/> from Virgil Services.
        /// </summary>
        /// <param name="card">The card to be revoked.</param>
        public async Task RevokeAsync(VirgilCard card)
        {
            var revokeRequest = new RevokeCardRequest(card.Id, RevocationReason.Unspecified);

            var appId  = this.context.Credentials.GetAppId();
            var appKey = this.context.Credentials.GetAppKey(this.context.Crypto);

            var fingerprint = this.context.Crypto.CalculateFingerprint(revokeRequest.Snapshot);
            var signature   = this.context.Crypto.Sign(fingerprint.GetValue(), appKey);

            revokeRequest.AppendSignature(appId, signature);

            await this.context.Client.RevokeCardAsync(revokeRequest);
        }
Пример #7
0
 /// <summary>
 /// Publishes a <see cref="VirgilCard"/> into application Virgil Services scope.
 /// </summary>
 /// <param name="card">The Card to be published.</param>
 public Task PublishAsync(VirgilCard card)
 {
     return(card.PublishAsync());
 }
Пример #8
0
 /// <summary>
 /// Publishes a <see cref="VirgilCard"/> into global Virgil Services scope.
 /// </summary>
 /// <param name="card">The Card to be published.</param>
 /// <param name="token">The identity validation token.</param>
 public Task PublishGlobalAsync(VirgilCard card, IdentityValidationToken token)
 {
     return(card.PublishAsGlobalAsync(token));
 }
Пример #9
0
 /// <summary>
 /// Verifies that a digital signature is valid for specified text.
 /// </summary>
 /// <param name="recipient">The <see cref="VirgilCard"/> recipient.</param>
 /// <param name="buffer">The text.</param>
 /// <param name="signature">The signature.</param>
 /// <returns><c>true</c> if the signature is valid; otherwise, <c>false</c>.</returns>
 /// <exception cref="ArgumentException"></exception>
 public static bool Verify(this VirgilCard recipient, VirgilBuffer buffer, VirgilBuffer signature)
 {
     return(recipient.Verify(buffer, signature));
 }
Пример #10
0
 /// <summary>
 /// Verifies that a digital signature is valid for specified text.
 /// </summary>
 /// <param name="recipient">The <see cref="VirgilCard"/> recipient.</param>
 /// <param name="data">The data to be signed.</param>
 /// <param name="signature">The signature.</param>
 /// <returns><c>true</c> if the signature is valid; otherwise, <c>false</c>.</returns>
 /// <exception cref="ArgumentException"></exception>
 public static bool Verify(this VirgilCard recipient, byte[] data, VirgilBuffer signature)
 {
     return(Verify(recipient, VirgilBuffer.From(data), signature));
 }
Пример #11
0
 /// <summary>
 /// Verifies that a digital signature is valid for specified text.
 /// </summary>
 /// <param name="recipient">The <see cref="VirgilCard"/> recipient.</param>
 /// <param name="text">The text.</param>
 /// <param name="signature">The signature.</param>
 /// <returns><c>true</c> if the signature is valid; otherwise, <c>false</c>.</returns>
 /// <exception cref="ArgumentException"></exception>
 public static bool Verify(this VirgilCard recipient, string text, VirgilBuffer signature)
 {
     return(Verify(recipient, VirgilBuffer.From(text), signature));
 }
Пример #12
0
 /// <summary>
 /// Encrypts the specified text for <paramref name="recipient"/> Card.
 /// </summary>
 /// <param name="recipient">The list of <see cref="VirgilCard"/> recipients.</param>
 /// <param name="bytes">The byte array to be encrypted.</param>
 /// <returns>A new <see cref="VirgilBuffer"/> with encrypted data.</returns>
 /// <exception cref="ArgumentNullException"></exception>
 public static VirgilBuffer Encrypt(this VirgilCard recipient, byte[] bytes)
 {
     return(recipient.Encrypt(new VirgilBuffer(bytes)));
 }
Пример #13
0
 /// <summary>
 /// Signs the plaintext using current <see cref="VirgilKey"/> and then encrypt it
 /// using recipient's <see cref="VirgilCard"/>.
 /// </summary>
 /// <param name="virgilKey">The <see cref="VirgilKey"/> used to sign the <paramref name="plaintext"/>.</param>
 /// <param name="plaintext">The plaintext to be encrypted.</param>
 /// <param name="recipient">The recipient's <see cref="VirgilCard"/> used to
 /// encrypt the <paramref name="plaintext"/>.</param>
 /// <returns>A new <see cref="VirgilBuffer"/> instance with encrypted data.</returns>
 public static VirgilBuffer SignThenEncrypt(this VirgilKey virgilKey, string plaintext, VirgilCard recipient)
 {
     return(virgilKey.SignThenEncrypt(VirgilBuffer.From(plaintext), new [] { recipient }));
 }
Пример #14
0
 /// <summary>
 /// Signs a byte array data using current <see cref="VirgilKey"/> and then encrypt it
 /// using recipient's <see cref="VirgilCard"/>.
 /// </summary>
 /// <param name="virgilKey">The <see cref="VirgilKey"/> used to sign the <paramref name="data"/>.</param>
 /// <param name="data">The plaintext to be encrypted.</param>
 /// <param name="recipient">The recipient's <see cref="VirgilCard"/> used to
 /// encrypt the <paramref name="data"/>.</param>
 /// <returns>A new <see cref="VirgilBuffer"/> instance with encrypted data.</returns>
 public static VirgilBuffer SignThenEncrypt(this VirgilKey virgilKey, byte[] data, VirgilCard recipient)
 {
     return(virgilKey.SignThenEncrypt(VirgilBuffer.From(data), new[] { recipient }));
 }
Пример #15
0
 /// <summary>
 /// Decrypts a ciphertext using current <see cref="VirgilKey"/> and verifies one
 /// using specified <see cref="VirgilCard"/>.
 /// </summary>
 /// <param name="virgilKey">The <see cref="VirgilKey"/>, that represents a Private key.</param>
 /// <param name="ciphertext">The ciphertext in base64 encoded string.</param>
 /// <param name="signerCard">The signer's <see cref="VirgilCard"/>, that represents a
 /// Public key and user/device information.</param>
 /// <returns>A new <see cref="VirgilBuffer"/> instance with decrypted data.</returns>
 public static VirgilBuffer DecryptThenVerify(this VirgilKey virgilKey, string ciphertext, VirgilCard signerCard)
 {
     return(virgilKey.DecryptThenVerify(VirgilBuffer.From(ciphertext, StringEncoding.Base64), signerCard));
 }
Пример #16
0
 /// <summary>
 /// Decrypts a ciphertext using current <see cref="VirgilKey"/> and verifies one
 /// using specified <see cref="VirgilCard"/>.
 /// </summary>
 /// <param name="virgilKey">The <see cref="VirgilKey"/>, that represents a Private key.</param>
 /// <param name="cipherdata">The ciphertext in base64 encoded string.</param>
 /// <param name="signerCard">The signer's <see cref="VirgilCard"/>, that represents a
 /// Public key and user/device information.</param>
 /// <returns>A new <see cref="VirgilBuffer"/> instance with decrypted data.</returns>
 public static VirgilBuffer DecryptThenVerify(this VirgilKey virgilKey, byte[] cipherdata, VirgilCard signerCard)
 {
     return(virgilKey.DecryptThenVerify(new VirgilBuffer(cipherdata), signerCard));
 }