Now i am programming with digital signature, and i have a problem when i generate the signature. I added KeyValue first, then add X509Data, but the tag just append first. I have a code for create 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;
}
and the result is:
<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>
and i want the result is:
<KeyInfo>
<KeyValue>
<RSAKeyValue>
<Modulus>
base 64 encode
</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
</KeyValue>
<X509Data>
<X509SubjectName>Name</X509SubjectName>
<X509Certificate>
base 64 endcode
</X509Certificate>
</X509Data>
</KeyInfo>
Who can help me. Thank you so much!