You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by sd...@apache.org on 2016/04/27 08:14:21 UTC
commons-crypto git commit: CRYPTO-11: UserGuide for the site document.
Repository: commons-crypto
Updated Branches:
refs/heads/master 9a1b871c8 -> 67d876622
CRYPTO-11: UserGuide for the site document.
Project: http://git-wip-us.apache.org/repos/asf/commons-crypto/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-crypto/commit/67d87662
Tree: http://git-wip-us.apache.org/repos/asf/commons-crypto/tree/67d87662
Diff: http://git-wip-us.apache.org/repos/asf/commons-crypto/diff/67d87662
Branch: refs/heads/master
Commit: 67d876622d7f9d4c47ff8b36b22f5cfa35f00ea4
Parents: 9a1b871
Author: Sun Dapeng <sd...@apache.org>
Authored: Wed Apr 27 14:11:21 2016 +0800
Committer: Sun Dapeng <sd...@apache.org>
Committed: Wed Apr 27 14:11:21 2016 +0800
----------------------------------------------------------------------
src/site/xdoc/userguide.xml | 179 +++++++++++++++++++--------------------
1 file changed, 85 insertions(+), 94 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-crypto/blob/67d87662/src/site/xdoc/userguide.xml
----------------------------------------------------------------------
diff --git a/src/site/xdoc/userguide.xml b/src/site/xdoc/userguide.xml
index bb7c899..0af471d 100644
--- a/src/site/xdoc/userguide.xml
+++ b/src/site/xdoc/userguide.xml
@@ -15,7 +15,6 @@
<author email="dev@commons.apache.org">Commons Documentation Team</author>
</properties>
<body>
- <!-- ================================================== -->
<section name="User guide">
<p>Apache Commons Crypto is a cryptographic library optimized with AES-NI
(Advanced Encryption
@@ -36,7 +35,6 @@
The interface for SecureRandom.
</td>
</tr>
-
<tr>
<td width="150">
<a href="apidocs/index.html">cipher
@@ -46,7 +44,6 @@
The interface of cryptographic cipher for encryption and decryption.
</td>
</tr>
-
<tr>
<td width="150">
<a href="apidocs/index.html">stream
@@ -58,9 +55,9 @@
read.
</td>
</tr>
-
</table>
</subsection>
+
<subsection name ="Usage">
<ol style="list-style-type: decimal">
<h4>Usage of Random API</h4>
@@ -70,24 +67,23 @@
for accelerating the random generation.
</p>
<table>
- <tr>
- <td>
- //Constructs a byte array to store random data.<br/>
- byte[] key = new byte[16];<br/>
- byte[] iv = new byte[16];<br/>
- Properties properties = new Properties();<br/>
- //Gets the 'SecureRandom' instance.<br/>
- SecureRandom secureRandom = SecureRandomFactory.getSecureRandom(properties);<br/>
- //Generates random bytes and places them into the byte array.<br/>
- secureRandom.nextBytes(key);<br/>
- secureRandom.nextBytes(iv);<br/>
- //Closes the SecureRandom.<br/>
- secureRandom.close();<br/>
- </td>
- </tr>
+ <tr>
+ <td>
+ //Constructs a byte array to store random data.<br/>
+ byte[] key = new byte[16];<br/>
+ byte[] iv = new byte[16];<br/>
+ Properties properties = new Properties();<br/>
+ //Gets the 'SecureRandom' instance.<br/>
+ SecureRandom secureRandom = SecureRandomFactory.getSecureRandom(properties);<br/>
+ //Generates random bytes and places them into the byte array.<br/>
+ secureRandom.nextBytes(key);<br/>
+ secureRandom.nextBytes(iv);<br/>
+ //Closes the SecureRandom.<br/>
+ secureRandom.close();<br/>
+ </td>
+ </tr>
</table>
-
<h4>Usage of Cipher API</h4>
<p>
Cipher provides an cryptographic interface for encryption and decryption.
@@ -97,52 +93,51 @@
</p>
<h5>Usage of Byte Array Encryption/Decryption</h5>
<table>
- <tr>
- <td>
- Properties properties = new Properties();<br/>
- //Creates a Cipher instance with the transformation and properties.<br/>
- Cipher cipher = Utils.getCipherInstance(CipherTransformation.AES_CTR_NOPADDING, properties);<br/><br/>
- String input = "hello world!";<br/>
- int inputOffset = 0;<br/>
- int inputLen = input.length();<br/>
- byte[] output = new byte[1024];<br/>
- int outputOffset = 0;<br/>
- //Initializes the cipher with ENCRYPT_MODE,key and iv.<br/>
- cipher.init(Cipher.ENCRYPT_MODE, key, iv);<br/>
- //Continues a multiple-part encryption/decryption operation for byte array.<br/>
- cipher.update(input.getBytes("UTF-8"), inputOffset, inputLen, output, outputOffset);<br/>
- //We should call do final at the end of encryption/decryption.<br/>
- cipher.doFinal(inBuffer, outBuffer);<br/>
- //Closes the cipher.<br/>
- cipher.close();
- </td>
- </tr>
+ <tr>
+ <td>
+ Properties properties = new Properties();<br/>
+ //Creates a Cipher instance with the transformation and properties.<br/>
+ Cipher cipher = Utils.getCipherInstance(CipherTransformation.AES_CTR_NOPADDING, properties);<br/><br/>
+ String input = "hello world!";<br/>
+ int inputOffset = 0;<br/>
+ int inputLen = input.length();<br/>
+ byte[] output = new byte[1024];<br/>
+ int outputOffset = 0;<br/>
+ //Initializes the cipher with ENCRYPT_MODE,key and iv.<br/>
+ cipher.init(Cipher.ENCRYPT_MODE, key, iv);<br/>
+ //Continues a multiple-part encryption/decryption operation for byte array.<br/>
+ cipher.update(input.getBytes("UTF-8"), inputOffset, inputLen, output, outputOffset);<br/>
+ //We should call do final at the end of encryption/decryption.<br/>
+ cipher.doFinal(inBuffer, outBuffer);<br/>
+ //Closes the cipher.<br/>
+ cipher.close();
+ </td>
+ </tr>
</table>
<h5>Usage of ByteBuffer Encryption/Decryption</h5>
<table>
- <tr>
- <td>
- Properties properties = new Properties();<br/>
- //Creates a Cipher instance with the transformation and properties.<br/>
- Cipher cipher = Utils.getCipherInstance(CipherTransformation.AES_CTR_NOPADDING, properties);<br/><br/>
- int bufferSize = 4096;<br/>
- ByteBuffer inBuffer = ByteBuffer.allocateDirect(bufferSize);<br/>
- ByteBuffer outBuffer = ByteBuffer.allocateDirect(bufferSize);<br/>
- inBuffer.put("The data you want to encrypt or decrypt".getBytes("UTF-8"));<br/>
- //Initializes the cipher with ENCRYPT_MODE,key and iv.<br/>
- cipher..init(Cipher.ENCRYPT_MODE, key, iv);<br/>
- //Continues a multiple-part encryption/decryption operation for byte array.<br/>
- cipher.update(inBuffer, outBuffer);<br/>
- //We should call do final at the end of encryption/decryption.<br/>
- cipher.doFinal(inBuffer, outBuffer);<br/>
- //Closes the cipher.<br/>
- cipher.close();
- </td>
- </tr>
+ <tr>
+ <td>
+ Properties properties = new Properties();<br/>
+ //Creates a Cipher instance with the transformation and properties.<br/>
+ Cipher cipher = Utils.getCipherInstance(CipherTransformation.AES_CTR_NOPADDING, properties);<br/><br/>
+ int bufferSize = 4096;<br/>
+ ByteBuffer inBuffer = ByteBuffer.allocateDirect(bufferSize);<br/>
+ ByteBuffer outBuffer = ByteBuffer.allocateDirect(bufferSize);<br/>
+ inBuffer.put("The data you want to encrypt or decrypt".getBytes("UTF-8"));<br/>
+ //Initializes the cipher with ENCRYPT_MODE,key and iv.<br/>
+ cipher.init(Cipher.ENCRYPT_MODE, key, iv);<br/>
+ //Continues a multiple-part encryption/decryption operation for byte array.<br/>
+ cipher.update(inBuffer, outBuffer);<br/>
+ //We should call do final at the end of encryption/decryption.<br/>
+ cipher.doFinal(inBuffer, outBuffer);<br/>
+ //Closes the cipher.<br/>
+ cipher.close();
+ </td>
+ </tr>
</table>
-
<h4>Usage of Stream API</h4>
<p>
Stream provides the data encryption and decryption in stream manner. We provide CipherInputStream,
@@ -151,47 +146,43 @@
</p>
<h5>Usage of stream encryption</h5>
<table>
- <tr>
- <td>
- int bufferSize = 4096;<br/>
- String input = "hello world!";<br/>
- byte[] decryptedData = new byte[1024];<br/>
- //Encryption with CipherOutputStream.<br/>
- //Initializes the cipher with ENCRYPT_MODE,key and iv.<br/>
- cipher.init(Cipher.ENCRYPT_MODE, key, iv);<br/>
- // Constructs the original OutputStream.<br/>
- OutputStream outputStream = new ByteArrayOutputStream();<br/>
- //Constructs the instance of CipherOutputStream.<br/>
- CipherOutputStream cos = new CipherOutputStream(outputStream, cipher, bufferSize, key, iv);<br/>
- cos.write(input.getBytes("UTF-8"));<br/>
- cos.flush();<br/>
- cos.close();<br/>
-
-
- </td>
- </tr>
+ <tr>
+ <td>
+ int bufferSize = 4096;<br/>
+ String input = "hello world!";<br/>
+ byte[] decryptedData = new byte[1024];<br/>
+ //Encryption with CipherOutputStream.<br/>
+ //Initializes the cipher with ENCRYPT_MODE,key and iv.<br/>
+ cipher.init(Cipher.ENCRYPT_MODE, key, iv);<br/>
+ // Constructs the original OutputStream.<br/>
+ OutputStream outputStream = new ByteArrayOutputStream();<br/>
+ //Constructs the instance of CipherOutputStream.<br/>
+ CipherOutputStream cos = new CipherOutputStream(outputStream, cipher, bufferSize, key, iv);<br/>
+ cos.write(input.getBytes("UTF-8"));<br/>
+ cos.flush();<br/>
+ cos.close();<br/>
+ </td>
+ </tr>
</table>
<h5>Usage of stream decryption</h5>
<table>
- <tr>
- <td>
- // Decryption with CipherInputStream.<br/>
- //Initializes the cipher with DECRYPT_MODE,key and iv.<br/>
- cipher.init(Cipher.DECRYPT_MODE, key, iv);<br/>
- //Constructs the original InputStream.<br/>
- InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());<br/>
- //Constructs the instance of CipherInputStream.<br/>
- CipherInputStream cis = new CipherInputStream(inputStream, cipher, bufferSize, key, iv);<br/>
- int decryptedLen = cis.read(decryptedData, 0, 1024);<br/>
- cis.close();<br/>
- </td>
- </tr>
+ <tr>
+ <td>
+ // Decryption with CipherInputStream.<br/>
+ //Initializes the cipher with DECRYPT_MODE,key and iv.<br/>
+ cipher.init(Cipher.DECRYPT_MODE, key, iv);<br/>
+ //Constructs the original InputStream.<br/>
+ InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());<br/>
+ //Constructs the instance of CipherInputStream.<br/>
+ CipherInputStream cis = new CipherInputStream(inputStream, cipher, bufferSize, key, iv);<br/>
+ int decryptedLen = cis.read(decryptedData, 0, 1024);<br/>
+ cis.close();<br/>
+ </td>
+ </tr>
</table>
</ol>
</subsection>
-
</section>
- <!-- ================================================== -->
</body>
</document>