Статус: Участник
Группы: Участники
Зарегистрирован: 22.01.2019(UTC) Сообщений: 15   Откуда: Санкт-Петербург Сказал «Спасибо»: 3 раз
|
Добрый день! Использую КриптоПро JCSP 5.0.45549-A. Делаю на базе XMLDSigRI enveloping подпись XML. Выдержка из вашего примера GenEnveloping.java: Код:
// First, create the DOM XMLSignatureFactory that will be used to
// generate the XMLSignature
XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM", XMLDSigRI.PROVIDER_NAME);
// Next, create a Reference to a same-document URI that is an Object
// element and specify the SHA1 digest algorithm
Reference ref = fac.newReference("#object",
fac.newDigestMethod(DigestMethod.SHA1, null),
Collections.singletonList(xmlSignFactory.newTransform("http://www.w3.org/TR/2001/REC-xml-c14n-20010315", (TransformParameterSpec) null))
);
// Next, create the referenced Object
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
// установка запрета на external entities
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
dbf.setNamespaceAware(true);
Document doc = dbf.newDocumentBuilder().newDocument();
Node text = doc.createTextNode("some text");
XMLStructure content = new DOMStructure(text);
XMLObject obj = fac.newXMLObject
(Collections.singletonList(content), "object", null, null);
// Create the SignedInfo
SignedInfo si = fac.newSignedInfo(
fac.newCanonicalizationMethod
(CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS,
(C14NMethodParameterSpec) null),
fac.newSignatureMethod(SignatureMethod.DSA_SHA1, null),
Collections.singletonList(ref));
// Create a DSA KeyPair
KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA");
kpg.initialize(512);
KeyPair kp = kpg.generateKeyPair();
// Create a KeyValue containing the DSA PublicKey that was generated
KeyInfoFactory kif = fac.getKeyInfoFactory();
KeyValue kv = kif.newKeyValue(kp.getPublic());
// Create a KeyInfo and add the KeyValue to it
KeyInfo ki = kif.newKeyInfo(Collections.singletonList(kv));
// Create the XMLSignature (but don't sign it yet)
XMLSignature signature = fac.newXMLSignature(si, ki,
Collections.singletonList(obj), null, null);
// Create a DOMSignContext and specify the DSA PrivateKey for signing
// and the document location of the XMLSignature
DOMSignContext dsc = new DOMSignContext(kp.getPrivate(), doc);
// Lastly, generate the enveloping signature using the PrivateKey
signature.sign(dsc);
// output the resulting document
OutputStream os;
if (args.length > 0) {
os = new FileOutputStream(args[0]);
} else {
os = System.out;
}
TransformerFactory tf = TransformerFactory.newInstance();
Transformer trans = tf.newTransformer();
trans.transform(new DOMSource(doc), new StreamResult(os));
Хочу вместо Код:
xmlSignFactory.newTransform("http://www.w3.org/TR/2001/REC-xml-c14n-20010315", (TransformParameterSpec) null)
fac.newCanonicalizationMethod
(CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS,
(C14NMethodParameterSpec) null)
Использовать свою реализацию канонизации и трансформации. Как мне зарегистрировать в XMLDSigRI свой алгоритм и реализацию канонизации и трансформации? Спасибо!
|
|
|
|
Быстрый переход
Вы не можете создавать новые темы в этом форуме.
Вы не можете отвечать в этом форуме.
Вы не можете удалять Ваши сообщения в этом форуме.
Вы не можете редактировать Ваши сообщения в этом форуме.
Вы не можете создавать опросы в этом форуме.
Вы не можете голосовать в этом форуме.
Important Information:
The Форум КриптоПро uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close