public class Utils
extends java.lang.Object
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static javax.xml.parsers.DocumentBuilderFactory |
createDocFactory()
create DocumentBuilderFactory with properties.
|
static org.w3c.dom.Document |
createEmptyDocument()
create new empty document.
|
static org.w3c.dom.Document |
createSampleDocument()
create new simple document to test.
|
static org.w3c.dom.Document |
decrypt(org.w3c.dom.Document doc,
java.security.Key kek,
java.lang.String encProvider)
decrypt document.
|
static org.w3c.dom.Document |
encrypt(org.w3c.dom.Document doc,
javax.crypto.SecretKey sessionKey,
org.apache.xml.security.encryption.EncryptedKey encryptedKey,
java.lang.String encProvider)
Зашифрование документа doc на sessionKey.
|
static org.w3c.dom.Document |
encrypt(org.w3c.dom.Document doc,
java.security.cert.X509Certificate cert,
java.lang.String encProvider,
ru.CryptoPro.JCP.params.CryptParamsSpec cryptParamsSpec)
encrypt document with kek
|
static org.w3c.dom.Document |
encrypt(org.w3c.dom.Document doc,
java.security.cert.X509Certificate cert,
java.lang.String encProvider,
ru.CryptoPro.JCP.params.CryptParamsSpec cryptParamsSpec,
java.lang.String transportAlg)
encrypt document with kek and transport algorithm
|
static org.w3c.dom.Document |
readDoc(java.io.File file)
load document from file.
|
static org.w3c.dom.Document |
readDoc(java.io.InputStream stream)
load document.
|
static org.w3c.dom.Document |
readDoc(java.lang.String file)
load document from file.
|
static void |
signDoc(org.w3c.dom.Document doc,
ru.CryptoPro.JCP.Key.KeyTwix twix)
Формирование подписи всего XML-документа для алгоритма ГОСТ Р 34.10-2001.
|
static void |
signDoc(org.w3c.dom.Document doc,
java.security.PrivateKey privateKey,
java.security.cert.X509Certificate cert)
Формирование подписи всего XML-документа для алгоритма ГОСТ Р 34.10-2001.
|
static void |
signDoc(org.w3c.dom.Document doc,
java.security.PrivateKey privateKey,
java.security.cert.X509Certificate cert,
java.lang.String signMethod,
java.lang.String digestMethod)
Формирование подписи всего XML-документа.
|
static void |
signDocURN(org.w3c.dom.Document doc,
ru.CryptoPro.JCP.Key.KeyTwix twix)
Формирование подписи всего XML-документа с новыми URN.
|
static void |
signDocURN(org.w3c.dom.Document doc,
java.security.PrivateKey privateKey,
java.security.cert.X509Certificate cert)
Формирование подписи XML-документа с новыми URN.
|
static org.apache.xml.security.encryption.EncryptedKey |
wrapKey(org.w3c.dom.Document doc,
javax.crypto.SecretKey sessionKey,
java.security.cert.X509Certificate cert,
java.lang.String encProvider,
java.lang.String transformAlg)
зашифрование сессионного ключа
sessionKey на ключе
kek и создание EncryptedKey с сертификатом. |
static void |
writeDoc(org.w3c.dom.Document doc,
java.io.File file)
save doc to file.
|
static void |
writeDoc(org.w3c.dom.Document doc,
java.io.OutputStream out)
save doc.
|
static void |
writeDoc(org.w3c.dom.Document doc,
java.lang.String fileName)
save doc to file.
|
public static javax.xml.parsers.DocumentBuilderFactory createDocFactory() throws javax.xml.parsers.ParserConfigurationException
javax.xml.parsers.ParserConfigurationException
public static void writeDoc(org.w3c.dom.Document doc, java.io.OutputStream out) throws javax.xml.transform.TransformerException
doc
- document to save.out
- output streamjavax.xml.transform.TransformerException
- If an unrecoverable error occurs during the
course of the transformation.public static void writeDoc(org.w3c.dom.Document doc, java.io.File file) throws java.io.IOException, javax.xml.transform.TransformerException
doc
- document to save.file
- to save tojava.io.IOException
- write errorjavax.xml.transform.TransformerException
- If an unrecoverable error occurs during the
course of the transformation. see writeDoc(org.w3c.dom.Document, java.io.OutputStream)
public static void writeDoc(org.w3c.dom.Document doc, java.lang.String fileName) throws java.io.IOException, javax.xml.transform.TransformerException
doc
- document to save.fileName
- to save tojava.io.IOException
- i/o errorjavax.xml.transform.TransformerException
- If an unrecoverable error occurs during the
course of the transformation. see writeDoc(org.w3c.dom.Document, java.io.OutputStream)
public static org.w3c.dom.Document readDoc(java.io.InputStream stream) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
stream
- to load document fromjavax.xml.parsers.ParserConfigurationException
- if a DocumentBuilder cannot be created
which satisfies the configuration requested.java.io.IOException
- If any IO errors occur.org.xml.sax.SAXException
- If any parse errors occur.public static org.w3c.dom.Document readDoc(java.io.File file) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
file
- to load document fromjavax.xml.parsers.ParserConfigurationException
- if a DocumentBuilder cannot be created
which satisfies the configuration requested.java.io.IOException
- If any IO errors occur.org.xml.sax.SAXException
- If any parse errors occur.public static org.w3c.dom.Document readDoc(java.lang.String file) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
file
- to load document fromjavax.xml.parsers.ParserConfigurationException
- if a DocumentBuilder cannot be created
which satisfies the configuration requested.java.io.IOException
- If any IO errors occur.org.xml.sax.SAXException
- If any parse errors occur.public static org.w3c.dom.Document createEmptyDocument() throws javax.xml.parsers.ParserConfigurationException
javax.xml.parsers.ParserConfigurationException
- if a DocumentBuilder cannot be created
which satisfies the configuration requested.public static org.w3c.dom.Document createSampleDocument() throws javax.xml.parsers.ParserConfigurationException
javax.xml.parsers.ParserConfigurationException
- if a DocumentBuilder cannot be created
which satisfies the configuration requested.public static void signDoc(org.w3c.dom.Document doc, java.security.PrivateKey privateKey, java.security.cert.X509Certificate cert, java.lang.String signMethod, java.lang.String digestMethod) throws java.lang.Exception
doc
- document to signprivateKey
- закрытый ключcert
- сертификатsignMethod
- алгоритм подписи (ГОСТ Р 34.10-2001)digestMethod
- алгоритм хеширования, используемый при подписи (ГОСТ Р
34.11-94)java.lang.Exception
- epublic static void signDoc(org.w3c.dom.Document doc, java.security.PrivateKey privateKey, java.security.cert.X509Certificate cert) throws java.lang.Exception
doc
- document to signprivateKey
- закрытый ключcert
- сертификатjava.lang.Exception
- epublic static void signDocURN(org.w3c.dom.Document doc, java.security.PrivateKey privateKey, java.security.cert.X509Certificate cert) throws java.lang.Exception
doc
- document to signprivateKey
- закрытый ключcert
- сертификатjava.lang.Exception
- epublic static void signDoc(org.w3c.dom.Document doc, ru.CryptoPro.JCP.Key.KeyTwix twix) throws java.lang.Exception
doc
- document to signtwix
- ключ и сертификат в одном флаконе 34.11-94)java.lang.Exception
- epublic static void signDocURN(org.w3c.dom.Document doc, ru.CryptoPro.JCP.Key.KeyTwix twix) throws java.lang.Exception
doc
- document to signtwix
- ключ и сертификат в одном флаконе 34.11-94)java.lang.Exception
- epublic static org.w3c.dom.Document encrypt(org.w3c.dom.Document doc, java.security.cert.X509Certificate cert, java.lang.String encProvider, ru.CryptoPro.JCP.params.CryptParamsSpec cryptParamsSpec) throws java.lang.Exception
doc
- document to encryptcert
- certencProvider
- encryption provider for session key
generation, encryption and exportcryptParamsSpec
- encryption parametersjava.lang.Exception
- encryption errorpublic static org.w3c.dom.Document encrypt(org.w3c.dom.Document doc, java.security.cert.X509Certificate cert, java.lang.String encProvider, ru.CryptoPro.JCP.params.CryptParamsSpec cryptParamsSpec, java.lang.String transportAlg) throws java.lang.Exception
doc
- document to encryptcert
- certencProvider
- encryption provider for session key
generation, encryption and exportcryptParamsSpec
- encryption parametersjava.lang.Exception
- encryption errorpublic static org.w3c.dom.Document encrypt(org.w3c.dom.Document doc, javax.crypto.SecretKey sessionKey, org.apache.xml.security.encryption.EncryptedKey encryptedKey, java.lang.String encProvider) throws java.lang.Exception
doc
- документ, который будем шифроватьsessionKey
- сессионный ключ шифрованияencryptedKey
- зашифрованный sessionKey будет добавлен в документencProvider
- провайдер для шифрованияjava.lang.Exception
- ошибки шифрованияpublic static org.apache.xml.security.encryption.EncryptedKey wrapKey(org.w3c.dom.Document doc, javax.crypto.SecretKey sessionKey, java.security.cert.X509Certificate cert, java.lang.String encProvider, java.lang.String transformAlg) throws java.lang.Exception
sessionKey
на ключе
kek
и создание EncryptedKey
с сертификатом.doc
- xml документsessionKey
- случайный сессионный ключ.cert
- сертификатencProvider
- провайдер для экспорта сессионного ключаjava.lang.Exception
- ошибки шифрованияpublic static org.w3c.dom.Document decrypt(org.w3c.dom.Document doc, java.security.Key kek, java.lang.String encProvider) throws java.lang.Exception
doc
- doc to decryptkek
- keyencProvider
- encryption providerjava.lang.Exception
- error