public void GenerateHash_Should_GenerateNonEmptyArray()
        {
            var crypto = new VirgilCrypto();
            var hash   = crypto.GenerateHash(Encoding.UTF8.GetBytes("hi"));

            Assert.AreNotEqual(hash, null);
        }
Beispiel #2
0
        public static Tuple <Jwt, JwtGenerator> PredefinedToken(
            this Faker faker,
            VirgilAccessTokenSigner signer,
            TimeSpan lifeTime,
            out string apiPublicKeyId,
            out string apiPublicKeyBase64)
        {
            var crypto      = new VirgilCrypto();
            var apiKeyPair  = crypto.GenerateKeys();
            var fingerprint = crypto.GenerateHash(crypto.ExportPublicKey(apiKeyPair.PublicKey));

            apiPublicKeyId = Bytes.ToString(fingerprint, StringEncoding.HEX);

            apiPublicKeyBase64 = Bytes.ToString(
                crypto.ExportPublicKey(apiKeyPair.PublicKey), StringEncoding.BASE64);

            var jwtGenerator = new JwtGenerator(
                faker.AppId(),
                apiKeyPair.PrivateKey,
                apiPublicKeyId,
                lifeTime,
                signer);

            var additionalData = new Dictionary <string, string>
            {
                { "username", "some_username" }
            };
            var dict  = additionalData.ToDictionary(entry => (object)entry.Key, entry => (object)entry.Value);
            var token = jwtGenerator.GenerateToken("some_identity", dict);

            return(new Tuple <Jwt, JwtGenerator>(token, jwtGenerator));
        }
        public void KeyPairId_Should_Be8BytesFromSha512FromPublicKey()
        {
            var crypto  = new VirgilCrypto();
            var keyPair = crypto.GenerateKeys();
            var keyId   = crypto.GenerateHash(keyPair.PublicKey.RawKey, HashAlgorithm.SHA512).Take(8).ToArray();

            Assert.AreEqual(keyPair.PrivateKey.Id, keyId);
            Assert.AreEqual(keyPair.PublicKey.Id, keyId);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("VirgilVersion=" + VirgilVersion.AsString());
            var crypto = new VirgilCrypto();
            var pythia = new Virgil.Crypto.Pythia.VirgilPythia();

            try
            {
                var hash = crypto.GenerateHash(Encoding.UTF8.GetBytes("hi"));
            }
            catch (Exception e)
            {
                Debug.Write(e.StackTrace);
            }

            NSApplication.Init();
            NSApplication.Main(args);
        }
        public IReadOnlyCollection <Valuable> DecryptValuablesCiphertext
        (
            FindValuablesProjection projection
        )
        {
            var virgilCrypto = new VirgilCrypto();

            SerilogLogger.Instance.Debug
            (
                "Generating the key hash. AppId='{AppId}'",
                _appId
            );

            var appKey = Convert.ToBase64String
                         (
                virgilCrypto.GenerateHash
                (
                    Encoding.UTF8.GetBytes
                    (
                        _appPassword
                    ),
                    HashAlgorithm.SHA512
                )
                         );

            SerilogLogger.Instance.Debug
            (
                "Importing the private key. AppId='{AppId}'",
                _appId
            );

            var privateKey = virgilCrypto.ImportPrivateKey
                             (
                Convert.FromBase64String(projection.PrivateKeyCiphertext),
                appKey
                             );

            SerilogLogger.Instance.Debug
            (
                "Decrypting the app settings. AppId='{AppId}'",
                _appId
            );

            var decrypted = Encoding.UTF8.GetString
                            (
                virgilCrypto.Decrypt
                (
                    Convert.FromBase64String(projection.Ciphertext),
                    privateKey
                )
                            );

            var valuables = JsonConvert.DeserializeObject <IReadOnlyCollection <Valuable> >
                            (
                decrypted
                            );

            AddOption
            (
                ConfigurKeys.SignalRAccessToken,
                projection.SignalR.AccessToken
            );

            AddOption
            (
                ConfigurKeys.SignalRUrl,
                projection.SignalR.Url
            );

            return(valuables);
        }