从证书中提取信息

发布于 2024-12-19 02:18:18 字数 1320 浏览 3 评论 0原文

我正在使用证书进行客户端身份验证(在示例 JSP 应用程序中)。 我编写了一段代码来从客户端证书中提取客户端信息。现在我想使用证书的序列号来识别数据库中的特定用途。

我使用提取序列号 <%= cert.getSerialNumber %> 它给了我一个输出 3。这是一个整数、BigInteger 还是数组值?

有什么方法可以将其声明为另一个整数变量,例如 int a = (序列号值)?我没有太多使用 jsp,所以我不知道在我的 jsp 文件中哪里有该代码。

如果有人能帮助我,我将非常感激。提前致谢。我附上我的代码,该代码从安装的证书中提取序列号。

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.math.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome</title>
</head>
<body>
<center> <font color="red"> Welcome</font> </center>
<%
Object o = request.getAttribute("javax.servlet.request.X509Certificate");
if (o != null) {
X509Certificate certs[] = (X509Certificate[]) o;
X509Certificate cert = certs[0];
%>   
<%= cert.getSerialNumber() %>             
<%   
}   
else {
%>
You are not Authorized!
Your certificate cannot be found!
<%
}
%>
<br><br>
<form method = "post" action = "page2.jsp">
<input type = submit value = "click me">
</form>
</body>
</html>

I am working on client authentication(in a sample JSP application) using certificates.
I have written a code to extract the client information from the client certificate. Now I wanted to use certificate's serial number to identify the particular use from the database.

I extract the serial number using
<%= cert.getSerialNumber %>
It gives me an output 3. Is this a integer, BigInteger or array value?

Is there any way I can declare this as an another integer variable for example int a = (serial number value)?? I have not played much with jsp so I do not know exactly where to have a code for that in my jsp file.

I would really appreciate if someone could help me. Thanks in advance. I am attaching my code which extracts the serial number from the certificate installed.

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.math.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome</title>
</head>
<body>
<center> <font color="red"> Welcome</font> </center>
<%
Object o = request.getAttribute("javax.servlet.request.X509Certificate");
if (o != null) {
X509Certificate certs[] = (X509Certificate[]) o;
X509Certificate cert = certs[0];
%>   
<%= cert.getSerialNumber() %>             
<%   
}   
else {
%>
You are not Authorized!
Your certificate cannot be found!
<%
}
%>
<br><br>
<form method = "post" action = "page2.jsp">
<input type = submit value = "click me">
</form>
</body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

影子的影子 2024-12-26 02:18:18

getSerialNumber() 方法返回一个 BigInteger 对象,根据 X509Certificate API。如果你想把这个值赋给一个变量,你可以简单地这样做:

BigInteger serialNumber = cert.getSerialNumber();

顺便说一句,这确实与 JSP 知识无关,这是核心 Java。

The getSerialNumber() method returns a BigInteger object, according to the X509Certificate API. If you want to assign this value to a variable, you can simply do:

BigInteger serialNumber = cert.getSerialNumber();

On a side note, this really has nothing to do with JSP knowledge, this is core Java.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文