internal static SecurityKey ResolveSecurityKey(SecurityKeyIdentifier ski, SecurityTokenResolver tokenResolver) { if (ski == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("ski"); } if (tokenResolver != null) { for (int i = 0; i < ski.Count; ++i) { SecurityKey key = null; if (tokenResolver.TryResolveSecurityKey(ski[i], out key)) { return(key); } } } if (ski.CanCreateKey) { return(ski.CreateKey()); } return(null); }
/// <summary> /// Attempts to resolve the _securityKeyIdentifier into a securityKey. If successful, the private _securityKey is set. /// Uses the tokenresolver that was passed in, it may be the case a keyIdentifier can /// generate a securityKey. A RSA key can generate a key with just the public part. /// </summary> /// <returns>void</returns> void ResolveKey() { if (_securityKeyIdentifier == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("ski"); } if (_securityKey == null) { lock (_keyLock) { if (_securityKey == null) { if (_securityTokenResolver != null) { for (int i = 0; i < _securityKeyIdentifier.Count; ++i) { if (_securityTokenResolver.TryResolveSecurityKey(_securityKeyIdentifier[i], out _securityKey)) { return; } } } // most likely a public key, do this last if (_securityKeyIdentifier.CanCreateKey) { _securityKey = _securityKeyIdentifier.CreateKey(); return; } throw DiagnosticUtility.ExceptionUtility.ThrowHelper( new SecurityTokenException(SR.GetString(SR.ID2080, _securityTokenResolver == null ? "null" : _securityTokenResolver.ToString(), _securityKeyIdentifier == null ? "null" : _securityKeyIdentifier.ToString())), System.Diagnostics.TraceEventType.Error); } } } }