<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FSecurity%2FFile_Secure_IO</id>
		<title>Java/Security/File Secure IO - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FSecurity%2FFile_Secure_IO"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Security/File_Secure_IO&amp;action=history"/>
		<updated>2026-04-22T01:51:44Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Security/File_Secure_IO&amp;diff=7605&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Security/File_Secure_IO&amp;diff=7605&amp;oldid=prev"/>
				<updated>2010-06-01T06:48:41Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:48, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/Security/File_Secure_IO&amp;diff=7604&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/Security/File_Secure_IO&amp;diff=7604&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:45Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Basic IO example using SHA1 ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.ByteArrayInputStream;&lt;br /&gt;
import java.io.ByteArrayOutputStream;&lt;br /&gt;
import java.security.DigestInputStream;&lt;br /&gt;
import java.security.DigestOutputStream;&lt;br /&gt;
import java.security.MessageDigest;&lt;br /&gt;
import java.security.Security;&lt;br /&gt;
import org.bouncycastle.jce.provider.BouncyCastleProvider;&lt;br /&gt;
/**&lt;br /&gt;
 * Basic IO example using SHA1&lt;br /&gt;
 */&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    Security.addProvider(new BouncyCastleProvider());        &lt;br /&gt;
    byte[] input = &amp;quot;www.jexp.ru&amp;quot;.getBytes();&lt;br /&gt;
    System.out.println(&amp;quot;input     : &amp;quot; + new String(input));    &lt;br /&gt;
    MessageDigest hash = MessageDigest.getInstance(&amp;quot;SHA1&amp;quot;);&lt;br /&gt;
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(input);&lt;br /&gt;
    DigestInputStream digestInputStream = new DigestInputStream(byteArrayInputStream, hash);&lt;br /&gt;
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();&lt;br /&gt;
    int ch;&lt;br /&gt;
    while ((ch = digestInputStream.read()) &amp;gt;= 0) {&lt;br /&gt;
      byteArrayOutputStream.write(ch);&lt;br /&gt;
    }&lt;br /&gt;
    byte[] newInput = byteArrayOutputStream.toByteArray();&lt;br /&gt;
    System.out.println(&amp;quot;in digest : &amp;quot; + new String(digestInputStream.getMessageDigest().digest()));&lt;br /&gt;
    byteArrayOutputStream = new ByteArrayOutputStream();&lt;br /&gt;
    DigestOutputStream digestOutputStream = new DigestOutputStream(byteArrayOutputStream, hash);&lt;br /&gt;
    digestOutputStream.write(newInput);&lt;br /&gt;
    digestOutputStream.close();&lt;br /&gt;
    System.out.println(&amp;quot;out digest: &amp;quot; + new String(digestOutputStream.getMessageDigest().digest()));&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Basic IO example with CTR using AES ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.ByteArrayInputStream;&lt;br /&gt;
import java.io.ByteArrayOutputStream;&lt;br /&gt;
import java.security.Security;&lt;br /&gt;
import javax.crypto.Cipher;&lt;br /&gt;
import javax.crypto.CipherInputStream;&lt;br /&gt;
import javax.crypto.CipherOutputStream;&lt;br /&gt;
import javax.crypto.spec.IvParameterSpec;&lt;br /&gt;
import javax.crypto.spec.SecretKeySpec;&lt;br /&gt;
/**&lt;br /&gt;
 * Basic IO example with CTR using AES&lt;br /&gt;
 */&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());        &lt;br /&gt;
    byte[] input = &amp;quot;www.jexp.ru&amp;quot;.getBytes();&lt;br /&gt;
    byte[] keyBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,&lt;br /&gt;
        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 };&lt;br /&gt;
    byte[] ivBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03, 0x00, 0x00, 0x00,&lt;br /&gt;
        0x00, 0x00, 0x00, 0x00, 0x01 };&lt;br /&gt;
    SecretKeySpec key = new SecretKeySpec(keyBytes, &amp;quot;AES&amp;quot;);&lt;br /&gt;
    IvParameterSpec ivSpec = new IvParameterSpec(ivBytes);&lt;br /&gt;
    Cipher cipher = Cipher.getInstance(&amp;quot;AES/CTR/NoPadding&amp;quot;, &amp;quot;BC&amp;quot;);&lt;br /&gt;
    System.out.println(&amp;quot;input : &amp;quot; + new String(input));&lt;br /&gt;
    // encryption pass&lt;br /&gt;
    cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec);&lt;br /&gt;
    ByteArrayInputStream bIn = new ByteArrayInputStream(input);&lt;br /&gt;
    CipherInputStream cIn = new CipherInputStream(bIn, cipher);&lt;br /&gt;
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();&lt;br /&gt;
    int ch;&lt;br /&gt;
    while ((ch = cIn.read()) &amp;gt;= 0) {&lt;br /&gt;
      bOut.write(ch);&lt;br /&gt;
    }&lt;br /&gt;
    byte[] cipherText = bOut.toByteArray();&lt;br /&gt;
    System.out.println(&amp;quot;cipher: &amp;quot; + new String(cipherText));&lt;br /&gt;
    // decryption pass&lt;br /&gt;
    cipher.init(Cipher.DECRYPT_MODE, key, ivSpec);&lt;br /&gt;
    bOut = new ByteArrayOutputStream();&lt;br /&gt;
    CipherOutputStream cOut = new CipherOutputStream(bOut, cipher);&lt;br /&gt;
    cOut.write(cipherText);&lt;br /&gt;
    cOut.close();&lt;br /&gt;
    System.out.println(&amp;quot;plain : &amp;quot; + new String(bOut.toByteArray()));&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== DES Crypter And Decryper File ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.InputStream;&lt;br /&gt;
import java.io.OutputStream;&lt;br /&gt;
import java.security.Security;&lt;br /&gt;
import java.security.spec.AlgorithmParameterSpec;&lt;br /&gt;
import javax.crypto.Cipher;&lt;br /&gt;
import javax.crypto.CipherInputStream;&lt;br /&gt;
import javax.crypto.CipherOutputStream;&lt;br /&gt;
import javax.crypto.KeyGenerator;&lt;br /&gt;
import javax.crypto.SecretKey;&lt;br /&gt;
import javax.crypto.spec.IvParameterSpec;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  static Cipher m_encrypter;&lt;br /&gt;
  static Cipher m_decrypter;&lt;br /&gt;
  public static void main(String args[]) throws Exception {&lt;br /&gt;
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());&lt;br /&gt;
    SecretKey key = KeyGenerator.getInstance(&amp;quot;DES&amp;quot;).generateKey();&lt;br /&gt;
    // for CBC; must be 8 bytes&lt;br /&gt;
    byte[] initVector = new byte[] { 0x10, 0x10, 0x01, 0x04, 0x01, 0x01, 0x01, 0x02 };&lt;br /&gt;
    AlgorithmParameterSpec algParamSpec = new IvParameterSpec(initVector);&lt;br /&gt;
    Cipher m_encrypter = Cipher.getInstance(&amp;quot;DES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
    Cipher m_decrypter = Cipher.getInstance(&amp;quot;DES/CBC/PKCS5Padding&amp;quot;);&lt;br /&gt;
    m_encrypter.init(Cipher.ENCRYPT_MODE, key, algParamSpec);&lt;br /&gt;
    m_decrypter.init(Cipher.DECRYPT_MODE, key, algParamSpec);&lt;br /&gt;
    FileInputStream fis = new FileInputStream(&amp;quot;cipherTest.in&amp;quot;);&lt;br /&gt;
    FileOutputStream fos = new FileOutputStream(&amp;quot;cipherTest.out&amp;quot;);&lt;br /&gt;
    int dataInputSize = fis.available();&lt;br /&gt;
    byte[] inputBytes = new byte[dataInputSize];&lt;br /&gt;
    fis.read(inputBytes);&lt;br /&gt;
    write(inputBytes, fos);&lt;br /&gt;
    fos.flush();&lt;br /&gt;
    fis.close();&lt;br /&gt;
    fos.close();&lt;br /&gt;
    String inputFileAsString = new String(inputBytes);&lt;br /&gt;
    System.out.println(&amp;quot;INPUT FILE CONTENTS\n&amp;quot; + inputFileAsString + &amp;quot;\n&amp;quot;);&lt;br /&gt;
    System.out.println(&amp;quot;File encrypted and saved to disk\n&amp;quot;);&lt;br /&gt;
    fis = new FileInputStream(&amp;quot;cipherTest.out&amp;quot;);&lt;br /&gt;
    byte[] decrypted = new byte[dataInputSize];&lt;br /&gt;
    read(decrypted, fis);&lt;br /&gt;
    fis.close();&lt;br /&gt;
    String decryptedAsString = new String(decrypted);&lt;br /&gt;
    System.out.println(&amp;quot;DECRYPTED FILE:\n&amp;quot; + decryptedAsString + &amp;quot;\n&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  public static void write(byte[] bytes, OutputStream out) throws Exception {&lt;br /&gt;
    CipherOutputStream cos = new CipherOutputStream(out, m_encrypter);&lt;br /&gt;
    cos.write(bytes, 0, bytes.length);&lt;br /&gt;
    cos.close();&lt;br /&gt;
  }&lt;br /&gt;
  public static void read(byte[] bytes, InputStream in) throws Exception {&lt;br /&gt;
    CipherInputStream cis = new CipherInputStream(in, m_decrypter);&lt;br /&gt;
    int pos = 0, intValue;&lt;br /&gt;
    while ((intValue = cis.read()) != -1) {&lt;br /&gt;
      bytes[pos] = (byte) intValue;&lt;br /&gt;
      pos++;&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
           &lt;br /&gt;
       &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>