[英]ADD certificate in HTTP Header
我想在 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)所以如果返回的编码响应会更大,服务器可能会返回错误响应。 即使我知道一些客户端/浏览器有不同的限制。
我很好奇你想实现什么,也许有更健壮的方法,比如在有效载荷中发送必要的证书或只发送证书签名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.