public async Task <bool> Execute()
        {
            var jsonWebKeys = await _jsonWebKeyRepository.GetAllAsync();

            if (jsonWebKeys == null ||
                !jsonWebKeys.Any())
            {
                return(false);
            }

            foreach (var jsonWebKey in jsonWebKeys)
            {
                var serializedRsa = string.Empty;
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    using (var provider = new RSACryptoServiceProvider())
                    {
                        serializedRsa = provider.ToXmlStringNetCore(true);
                    }
                }
                else
                {
                    using (var rsa = new RSAOpenSsl())
                    {
                        serializedRsa = rsa.ToXmlStringNetCore(true);
                    }
                }

                jsonWebKey.SerializedKey = serializedRsa;
                await _jsonWebKeyRepository.UpdateAsync(jsonWebKey);
            }

            return(true);
        }
Esempio n. 2
0
        public async Task <bool> Execute()
        {
            var jsonWebKeys = await _jsonWebKeyRepository.GetAllAsync();

            if (jsonWebKeys == null ||
                !jsonWebKeys.Any())
            {
                return(false);
            }

            foreach (var jsonWebKey in jsonWebKeys)
            {
                var serializedRsa = string.Empty;
#if NET46
                using (var provider = new RSACryptoServiceProvider())
                {
                    serializedRsa = provider.ToXmlString(true);
                }
#else
                using (var rsa = new RSAOpenSsl())
                {
                    serializedRsa = rsa.ToXmlString(true);
                }
#endif

                jsonWebKey.SerializedKey = serializedRsa;
                await _jsonWebKeyRepository.UpdateAsync(jsonWebKey);
            }

            return(true);
        }
        public async Task <List <Dictionary <string, object> > > Execute()
        {
            var result      = new List <Dictionary <string, object> >();
            var jsonWebKeys = await _jsonWebKeyRepository.GetAllAsync();

            // Retrieve all the JWK used by the client to encrypt the JWS
            var jsonWebKeysUsedForEncryption = jsonWebKeys.Where(jwk => jwk.Use == Use.Enc && jwk.KeyOps.Contains(KeyOperations.Encrypt));

            foreach (var jsonWebKey in jsonWebKeysUsedForEncryption)
            {
                var publicKeyInformation  = _jsonWebKeyEnricher.GetPublicKeyInformation(jsonWebKey);
                var jsonWebKeyInformation = _jsonWebKeyEnricher.GetJsonWebKeyInformation(jsonWebKey);
                // jsonWebKeyInformation.Add(Jwt.Constants.JsonWebKeyParameterNames.KeyOperationsName, new List<string> { Jwt.Constants.MappingKeyOperationToName[KeyOperations.Encrypt] } );
                publicKeyInformation.AddRange(jsonWebKeyInformation);
                result.Add(publicKeyInformation);
            }

            return(result);
        }
Esempio n. 4
0
        public async Task <List <Dictionary <string, object> > > Execute()
        {
            var result      = new List <Dictionary <string, object> >();
            var jsonWebKeys = await _jsonWebKeyRepository.GetAllAsync();

            foreach (var jsonWebKey in jsonWebKeys)
            {
                var publicKeyInformation  = _jsonWebKeyEnricher.GetPublicKeyInformation(jsonWebKey);
                var jsonWebKeyInformation = _jsonWebKeyEnricher.GetJsonWebKeyInformation(jsonWebKey);
                foreach (var jwk in jsonWebKeyInformation)
                {
                    publicKeyInformation.Add(jwk.Key, jwk.Value);
                }

                result.Add(publicKeyInformation);
            }

            return(result);
        }