Несоответствующее значение модуля в элементах RSAPubKey - PullRequest
0 голосов
/ 26 июня 2019

Я пытаюсь представить копию моего RSAKeyValue в subjectConfirmationData моего утверждения SAML. Текст KeyInfo-KeyValue-RSAKeyValue-Modulus, который я использую в кодировке Base64, не соответствует значению в KeyInfo, созданном java xmlsignature, который подписывает утверждение.

Подпись подтверждения (this.rsaPubKey имеет тип RSAPublicKey):

// now we can sign it
XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");            

// Create the DOMSignContext by specifying the signing informations: Private Key, Node to be signed, Where to insert the Signature.
DOMSignContext dsc = new DOMSignContext(privateKey, assertionRoot, subject);
dsc.setDefaultNamespacePrefix("ds");

KeyInfoFactory kif = fac.getKeyInfoFactory();
KeyValue kv = kif.newKeyValue(this.rsaPubKey);

Вот так я пытаюсь создать KeyInfo в теме ConfirmationData:

// - ds:KeyInfo
Element keyInfo = securityDoc.createElementNS("http://www.w3.org/2000/09/xmldsig#","ds:KeyInfo");
subjectConfirmationData.appendChild(keyInfo);
// - keyvalue
Element keyValue = securityDoc.createElementNS("http://www.w3.org/2000/09/xmldsig#","ds:KeyValue");
keyInfo.appendChild(keyValue);
// - RSAKeyValue
Element rsaKeyValue = securityDoc.createElementNS("http://www.w3.org/2000/09/xmldsig#","ds:RSAKeyValue");
keyValue.appendChild(rsaKeyValue);
// - modulus
Element modulusKey = securityDoc.createElementNS("http://www.w3.org/2000/09/xmldsig#","ds:Modulus");
modulusKey.setTextContent(Base64.getEncoder().encodeToString(rsaPubKey.getModulus().toByteArray()));            
// exponent
Element exponentKey = securityDoc.createElementNS("http://www.w3.org/2000/09/xmldsig#","ds:Exponent");
exponentKey.setTextContent(Base64.getEncoder().encodeToString(rsaPubKey.getPublicExponent().toByteArray()));
rsaKeyValue.appendChild(exponentKey);

При использовании этого метода результирующие значения в элементе не совпадают даже близко. Что мне не хватает в моей обработке Base64?

...