现在我正在使用数字签名进行编程,并且在生成签名时遇到了问题。我先添加了 KeyValue,然后添加了 X509Data,但标签只是先附加。我有一个创建signinfo的代码:
private KeyInfo createKeyInfo(PublicKey publicKey, X509Certificate x509Certificate) throws KeyException {
KeyInfoFactory keyInfoFactory = factory.getKeyInfoFactory();
KeyInfo keyInfo = null;
KeyValue keyValue = null;
List items = null;
//Just with public key
if(publicKey != null){
keyValue = keyInfoFactory.newKeyValue(publicKey);
keyInfo = keyInfoFactory.newKeyInfo(singletonList(keyValue));
}
if(x509Certificate != null){
List x509list = new ArrayList();
x509list.add(x509Certificate.getSubjectX500Principal().getName());
x509list.add(x509Certificate);
X509Data x509Data = keyInfoFactory.newX509Data(x509list);
items = new ArrayList();
items.add(x509Data);
if(keyValue != null){
items.add(keyValue);
}
keyInfo = keyInfoFactory.newKeyInfo(items);
}
return keyInfo;
}
结果是:
<KeyInfo>
<X509Data>
<X509SubjectName>name</X509SubjectName>
<X509Certificate>
base 64 encode
</X509Certificate>
</X509Data>
<KeyValue>
<RSAKeyValue>
<Modulus>
base 64 encode key
</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
</KeyValue>
</KeyInfo>
我想要的结果是:
<KeyInfo>
<KeyValue>
<RSAKeyValue>
<Modulus>
base 64 encode
</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
</KeyValue>
<X509Data>
<X509SubjectName>Name</X509SubjectName>
<X509Certificate>
base 64 endcode
</X509Certificate>
</X509Data>
</KeyInfo>
谁能帮我。太感谢了!