如何从 RSA public 密钥 XML 文件中获取 n 值.net core c#
How to get n value from RSA public key XML file .net core c#
JWKS 端点的 n 值是多少。
如何从 .net core c# 中的 RSA public 密钥 XML 文件中获取 n 值。
这是我的 RSA public 密钥。
<RSAKeyValue><Modulus>w2EmXqTfj7LDHtN8/H6I1XAOW5bnH2j0IYDK2VSg0kd+TtCJDh/rogV/ouxGBYoyr6pEtuOQsQyIYcUWektRL+/hVHPZzw9VTNtxGpgYZoVjFH1TB+acJ5wz7eOAybLdEHA4/F7A9VyvlRDir6AuuXcqF4yU0G3Ew21bFzRT7S0hDMMmHCsKwvi33lFkWkMFNnXVwQMdWu59jgksMvTQDWpFveUBr1E4R9FRYmrQPe4hMrjijlmS86xBTn3Qasd6qnT2uW137uwtC2aaqWS/Q8BGBbDpOxiMxffrGLyr3Xos1dOCgqx+oE/ZW6+CGhC+F4My/2EZNciyGhtt4N5abQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>
模数为 n,指数为 e,另请参阅 here
几行,使用LINQ to XML,你可以提取值:
using System;
using System.Xml.Linq;
namespace RSAXML
{
class Program
{
static void Main(string[] args)
{
string RSAKey = "<RSAKeyValue><Modulus>w2EmXqTfj7LDHtN8/H6I1XAOW5bnH2j0IYDK2VSg0kd+TtCJDh/rogV/ouxGBYoyr6pEtuOQsQyIYcUWektRL+/hVHPZzw9VTNtxGpgYZoVjFH1TB+acJ5wz7eOAybLdEHA4/F7A9VyvlRDir6AuuXcqF4yU0G3Ew21bFzRT7S0hDMMmHCsKwvi33lFkWkMFNnXVwQMdWu59jgksMvTQDWpFveUBr1E4R9FRYmrQPe4hMrjijlmS86xBTn3Qasd6qnT2uW137uwtC2aaqWS/Q8BGBbDpOxiMxffrGLyr3Xos1dOCgqx+oE/ZW6+CGhC+F4My/2EZNciyGhtt4N5abQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
XElement RSAKeyXML = XElement.Parse(RSAKey);
string Modulus = RSAKeyXML.Element("Modulus").Value.ToString();
Console.WriteLine(Modulus);
}
}
}
结果:
w2EmXqTfj7LDHtN8/H6I1XAOW5bnH2j0IYDK2VSg0kd+TtCJDh/rogV/ouxGBYoyr6pEtuOQsQyIYcUWektRL+/hVHPZzw9VTNtxGpgYZoVjFH1TB+acJ5wz7eOAybLdEHA4/F7A9VyvlRDir6AuuXcqF4yU0G3Ew21bFzRT7S0hDMMmHCsKwvi33lFkWkMFNnXVwQMdWu59jgksMvTQDWpFveUBr1E4R9FRYmrQPe4hMrjijlmS86xBTn3Qasd6qnT2uW137uwtC2aaqWS/Q8BGBbDpOxiMxffrGLyr3Xos1dOCgqx+oE/ZW6+CGhC+F4My/2EZNciyGhtt4N5abQ==
在此您可以看到如何根据模数和指数导入密钥。
JWKS 端点的 n 值是多少。
如何从 .net core c# 中的 RSA public 密钥 XML 文件中获取 n 值。
这是我的 RSA public 密钥。
<RSAKeyValue><Modulus>w2EmXqTfj7LDHtN8/H6I1XAOW5bnH2j0IYDK2VSg0kd+TtCJDh/rogV/ouxGBYoyr6pEtuOQsQyIYcUWektRL+/hVHPZzw9VTNtxGpgYZoVjFH1TB+acJ5wz7eOAybLdEHA4/F7A9VyvlRDir6AuuXcqF4yU0G3Ew21bFzRT7S0hDMMmHCsKwvi33lFkWkMFNnXVwQMdWu59jgksMvTQDWpFveUBr1E4R9FRYmrQPe4hMrjijlmS86xBTn3Qasd6qnT2uW137uwtC2aaqWS/Q8BGBbDpOxiMxffrGLyr3Xos1dOCgqx+oE/ZW6+CGhC+F4My/2EZNciyGhtt4N5abQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>
模数为 n,指数为 e,另请参阅 here
几行,使用LINQ to XML,你可以提取值:
using System;
using System.Xml.Linq;
namespace RSAXML
{
class Program
{
static void Main(string[] args)
{
string RSAKey = "<RSAKeyValue><Modulus>w2EmXqTfj7LDHtN8/H6I1XAOW5bnH2j0IYDK2VSg0kd+TtCJDh/rogV/ouxGBYoyr6pEtuOQsQyIYcUWektRL+/hVHPZzw9VTNtxGpgYZoVjFH1TB+acJ5wz7eOAybLdEHA4/F7A9VyvlRDir6AuuXcqF4yU0G3Ew21bFzRT7S0hDMMmHCsKwvi33lFkWkMFNnXVwQMdWu59jgksMvTQDWpFveUBr1E4R9FRYmrQPe4hMrjijlmS86xBTn3Qasd6qnT2uW137uwtC2aaqWS/Q8BGBbDpOxiMxffrGLyr3Xos1dOCgqx+oE/ZW6+CGhC+F4My/2EZNciyGhtt4N5abQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
XElement RSAKeyXML = XElement.Parse(RSAKey);
string Modulus = RSAKeyXML.Element("Modulus").Value.ToString();
Console.WriteLine(Modulus);
}
}
}
结果:
w2EmXqTfj7LDHtN8/H6I1XAOW5bnH2j0IYDK2VSg0kd+TtCJDh/rogV/ouxGBYoyr6pEtuOQsQyIYcUWektRL+/hVHPZzw9VTNtxGpgYZoVjFH1TB+acJ5wz7eOAybLdEHA4/F7A9VyvlRDir6AuuXcqF4yU0G3Ew21bFzRT7S0hDMMmHCsKwvi33lFkWkMFNnXVwQMdWu59jgksMvTQDWpFveUBr1E4R9FRYmrQPe4hMrjijlmS86xBTn3Qasd6qnT2uW137uwtC2aaqWS/Q8BGBbDpOxiMxffrGLyr3Xos1dOCgqx+oE/ZW6+CGhC+F4My/2EZNciyGhtt4N5abQ==
在此