从证书中提取信息
我正在使用证书进行客户端身份验证(在示例 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
getSerialNumber()
方法返回一个BigInteger
对象,根据 X509Certificate API。如果你想把这个值赋给一个变量,你可以简单地这样做:顺便说一句,这确实与 JSP 知识无关,这是核心 Java。
The
getSerialNumber()
method returns aBigInteger
object, according to the X509Certificate API. If you want to assign this value to a variable, you can simply do:On a side note, this really has nothing to do with JSP knowledge, this is core Java.