java - 在 HTTP 标头中添加证书
问题描述
我想在 http 标头中添加一个证书。我的问题是:
- 我们必须将它作为字节数组发送吗?还是作为字符串?
- 如果是,java.securit.PublicKey 的 toString 方法是否构建了良好的字符串表示?
- 插入http头是不是太长了?谢谢
代码 :
public byte [] getCertificate() throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {
if (Configuration.getSignaturekeyStoreLocation()==null || ewalletConfiguration.getSignaturekeyStoreLocation().isEmpty()) {
throw new IllegalArgumentException("Keystore url must not be null");
}
FileInputStream is = new FileInputStream(Configuration.getSignaturekeyStoreLocation());
char[] keyPassword = ewalletConfiguration.getSignaturekeyStorePassword().toCharArray();
KeyStore keystore = KeyStore.getInstance("JKS");
//keyStore Password
keystore.load(is, keyPassword);
//
final Certificate cert = (Certificate) keystore.getCertificate(Configuration.getSignatureCertificateAlias());
return cert.getEncoded();
}``
`
解决方案
为什么在标头中有证书有不同的目的,所以如果你解释用例会更简单。
我们必须将它作为字节数组发送吗?还是作为字符串?
HTTP 标头始终是一个字符串,我假设您需要使用 base64 编码。
如果是,java.securit.PublicKey 的 toString 方法是否构建了良好的字符串表示?
不,公钥只是一个公钥,而不是整个证书(证书包含公钥)。获取 (x509) 证书表示的最简单方法是使用getEncoded方法
插入http头是不是太长了?谢谢
它可能。通常http服务器有一定的头缓冲区(例如apache tomat有/有默认的8kB缓冲区,IIS 16kB)所以如果返回的编码响应会更大,服务器可能会返回一个错误响应。即使我知道一些客户端/浏览器有不同的限制。
我很好奇您想要实现什么,也许有更强大的方法,例如在有效负载中发送必要的证书或仅发送证书签名
推荐阅读
- python - Python Scraping:无论如何,我可以使用 beautifulsoup 来抓取这行代码吗?(查找包含特定标签/字符串的标签内容)
- flutter - 颤振 Gradle 任务组装调试失败
- pyspark - 如何使用 PySpark 中的二元组/n-gram 算法到达字符列表?
- ios - xamarin.forms 自今天更新 (15.9.2021) 以来无法再发布到应用商店显示图标大小错误
- spring - Mockito Powermock 不模拟构造函数
- google-cloud-firestore - 尝试从我的 Google 云功能访问我的 Firestore 数据库,但我在服务器日志中不断收到错误消息
- r - 将 r 中的绘图保存在 PowerPoint 的图层中
- asp.net - 选择下拉列表错误 500 时,aspx.vb 页面不起作用
- python - 如何使用python按分钟制作日历事件图
- multithreading - 使用 IServiceScopeFactory 为多线程创建 Scoped DB 上下文的缺点