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

	<entry>
		<id>http://jexp.ru/index.php?title=Java_Tutorial/Security/Encrypt_Decrypt&amp;diff=4316&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/Security/Encrypt_Decrypt&amp;diff=4316&amp;oldid=prev"/>
				<updated>2010-06-01T05:01:35Z</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;Версия 05:01, 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://jexp.ru/index.php?title=Java_Tutorial/Security/Encrypt_Decrypt&amp;diff=4315&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/Security/Encrypt_Decrypt&amp;diff=4315&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:27Z</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;==  Blowfish Decrypt ==&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.BufferedInputStream;&lt;br /&gt;
import java.io.BufferedOutputStream;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.ObjectInputStream;&lt;br /&gt;
import javax.crypto.Cipher;&lt;br /&gt;
import javax.crypto.CipherInputStream;&lt;br /&gt;
import javax.crypto.SecretKey;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    blowfishEncrypt(&amp;quot;ciphertextfile&amp;quot;, &amp;quot;plaintextfile&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  public static void blowfishEncrypt(String f1, String f2) throws Exception {&lt;br /&gt;
    SecretKey key = null;&lt;br /&gt;
    ObjectInputStream keyFile = new ObjectInputStream(new FileInputStream(&amp;quot;BlowfishKey.ser&amp;quot;));&lt;br /&gt;
    key = (SecretKey) keyFile.readObject();&lt;br /&gt;
    keyFile.close();&lt;br /&gt;
    Cipher cipher = Cipher.getInstance(&amp;quot;Blowfish/ECB/PKCS5Padding&amp;quot;);&lt;br /&gt;
    cipher.init(Cipher.DECRYPT_MODE, key);&lt;br /&gt;
    CipherInputStream in = new CipherInputStream(new BufferedInputStream(new FileInputStream(f1)),&lt;br /&gt;
        cipher);&lt;br /&gt;
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f2));&lt;br /&gt;
    int i;&lt;br /&gt;
    do {&lt;br /&gt;
      i = in.read();&lt;br /&gt;
      if (i != -1)&lt;br /&gt;
        out.write(i);&lt;br /&gt;
    } while (i &amp;gt; 0);&lt;br /&gt;
    in.close();&lt;br /&gt;
    out.close();&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;
==  Blowfish Encrypt ==&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.BufferedInputStream;&lt;br /&gt;
import java.io.BufferedOutputStream;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.ObjectInputStream;&lt;br /&gt;
import java.io.ObjectOutputStream;&lt;br /&gt;
import javax.crypto.Cipher;&lt;br /&gt;
import javax.crypto.CipherOutputStream;&lt;br /&gt;
import javax.crypto.KeyGenerator;&lt;br /&gt;
import javax.crypto.SecretKey;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    blowfishEncrypt(&amp;quot;plaintextfile&amp;quot;, &amp;quot;ciphertextfile&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  public static void blowfishEncrypt(String f1, String f2) throws Exception {&lt;br /&gt;
    SecretKey key = null;&lt;br /&gt;
    ObjectInputStream keyFile = new ObjectInputStream(new FileInputStream(&amp;quot;BlowfishKey.ser&amp;quot;));&lt;br /&gt;
    key = (SecretKey) keyFile.readObject();&lt;br /&gt;
    keyFile.close();&lt;br /&gt;
    KeyGenerator keygen = KeyGenerator.getInstance(&amp;quot;Blowfish&amp;quot;);&lt;br /&gt;
    key = keygen.generateKey();&lt;br /&gt;
    ObjectOutputStream keyFileOut = new ObjectOutputStream(new FileOutputStream(&amp;quot;BlowfishKey.ser&amp;quot;));&lt;br /&gt;
    keyFileOut.writeObject(key);&lt;br /&gt;
    keyFileOut.close();&lt;br /&gt;
    Cipher cipher = Cipher.getInstance(&amp;quot;Blowfish/ECB/PKCS5Padding&amp;quot;);&lt;br /&gt;
    cipher.init(Cipher.ENCRYPT_MODE, key);&lt;br /&gt;
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(f1));&lt;br /&gt;
    CipherOutputStream out = new CipherOutputStream(new BufferedOutputStream(new FileOutputStream(&lt;br /&gt;
        f2)), cipher);&lt;br /&gt;
    int i;&lt;br /&gt;
    do {&lt;br /&gt;
      i = in.read();&lt;br /&gt;
      if (i != -1)&lt;br /&gt;
        out.write(i);&lt;br /&gt;
    } while (i != -1);&lt;br /&gt;
    in.close();&lt;br /&gt;
    out.close();&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;
==  DES Encrypt Console ==&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.BufferedInputStream;&lt;br /&gt;
import java.io.BufferedOutputStream;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.ObjectInputStream;&lt;br /&gt;
import java.io.ObjectOutputStream;&lt;br /&gt;
import javax.crypto.Cipher;&lt;br /&gt;
import javax.crypto.CipherOutputStream;&lt;br /&gt;
import javax.crypto.KeyGenerator;&lt;br /&gt;
import javax.crypto.SecretKey;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    desEncrypt(&amp;quot;plaintextfile&amp;quot;, &amp;quot;ciphertextfile&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  public static void desEncrypt(String f1, String f2) throws Exception {&lt;br /&gt;
    SecretKey key = null;&lt;br /&gt;
    ObjectInputStream keyFile = new ObjectInputStream(new FileInputStream(&amp;quot;DESKey.ser&amp;quot;));&lt;br /&gt;
    key = (SecretKey) keyFile.readObject();&lt;br /&gt;
    keyFile.close();&lt;br /&gt;
    KeyGenerator keygen = KeyGenerator.getInstance(&amp;quot;DES&amp;quot;);&lt;br /&gt;
    key = keygen.generateKey();&lt;br /&gt;
    ObjectOutputStream keyFileout = new ObjectOutputStream(new FileOutputStream(&amp;quot;DESKey.ser&amp;quot;));&lt;br /&gt;
    keyFileout.writeObject(key);&lt;br /&gt;
    keyFileout.close();&lt;br /&gt;
    Cipher cipher = null;&lt;br /&gt;
    cipher = Cipher.getInstance(&amp;quot;DES/ECB/PKCS5Padding&amp;quot;);&lt;br /&gt;
    cipher.init(Cipher.ENCRYPT_MODE, key);&lt;br /&gt;
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(f1));&lt;br /&gt;
    CipherOutputStream out = new CipherOutputStream(new BufferedOutputStream(new FileOutputStream(&lt;br /&gt;
        f2)), cipher);&lt;br /&gt;
    int i;&lt;br /&gt;
    do {&lt;br /&gt;
      i = in.read();&lt;br /&gt;
      if (i != -1)&lt;br /&gt;
        out.write(i);&lt;br /&gt;
    } while (i != -1);&lt;br /&gt;
    in.close();&lt;br /&gt;
    out.close();&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;
==  Generate a random String suitable for use as a temporary password ==&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;
/*&lt;br /&gt;
    JSPWiki - a JSP-based WikiWiki clone.&lt;br /&gt;
    Licensed to the Apache Software Foundation (ASF) under one&lt;br /&gt;
    or more contributor license agreements.  See the NOTICE file&lt;br /&gt;
    distributed with this work for additional information&lt;br /&gt;
    regarding copyright ownership.  The ASF licenses this file&lt;br /&gt;
    to you under the Apache License, Version 2.0 (the&lt;br /&gt;
    &amp;quot;License&amp;quot;); you may not use this file except in compliance&lt;br /&gt;
    with the License.  You may obtain a copy of the License at&lt;br /&gt;
       http://www.apache.org/licenses/LICENSE-2.0&lt;br /&gt;
    Unless required by applicable law or agreed to in writing,&lt;br /&gt;
    software distributed under the License is distributed on an&lt;br /&gt;
    &amp;quot;AS IS&amp;quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY&lt;br /&gt;
    KIND, either express or implied.  See the License for the&lt;br /&gt;
    specific language governing permissions and limitations&lt;br /&gt;
    under the License.    &lt;br /&gt;
 */&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.util.Random;&lt;br /&gt;
public class StringUtils&lt;br /&gt;
{&lt;br /&gt;
  private static final Random RANDOM = new SecureRandom();&lt;br /&gt;
  /** Length of password. @see #generateRandomPassword() */&lt;br /&gt;
  public static final int PASSWORD_LENGTH = 8;&lt;br /&gt;
  /**&lt;br /&gt;
   * Generate a random String suitable for use as a temporary password.&lt;br /&gt;
   *&lt;br /&gt;
   * @return String suitable for use as a temporary password&lt;br /&gt;
   * @since 2.4&lt;br /&gt;
   */&lt;br /&gt;
  public static String generateRandomPassword()&lt;br /&gt;
  {&lt;br /&gt;
      // Pick from some letters that won&amp;quot;t be easily mistaken for each&lt;br /&gt;
      // other. So, for example, omit o O and 0, 1 l and L.&lt;br /&gt;
      String letters = &amp;quot;abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789+@&amp;quot;;&lt;br /&gt;
      String pw = &amp;quot;&amp;quot;;&lt;br /&gt;
      for (int i=0; i&amp;lt;PASSWORD_LENGTH; i++)&lt;br /&gt;
      {&lt;br /&gt;
          int index = (int)(RANDOM.nextDouble()*letters.length());&lt;br /&gt;
          pw += letters.substring(index, index+1);&lt;br /&gt;
      }&lt;br /&gt;
      return pw;&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;
==  Use DES to Decrypt ==&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.BufferedInputStream;&lt;br /&gt;
import java.io.BufferedOutputStream;&lt;br /&gt;
import java.io.FileInputStream;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.io.ObjectInputStream;&lt;br /&gt;
import javax.crypto.Cipher;&lt;br /&gt;
import javax.crypto.CipherInputStream;&lt;br /&gt;
import javax.crypto.SecretKey;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    desEncrypt(&amp;quot;plaintextfile&amp;quot;, &amp;quot;ciphertextfile&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  public static void desEncrypt(String f1, String f2) throws Exception {&lt;br /&gt;
    SecretKey key = null;&lt;br /&gt;
    ObjectInputStream keyFile = new ObjectInputStream(new FileInputStream(&amp;quot;DESKey.ser&amp;quot;));&lt;br /&gt;
    key = (SecretKey) keyFile.readObject();&lt;br /&gt;
    keyFile.close();&lt;br /&gt;
    Cipher cipher = Cipher.getInstance(&amp;quot;DES/ECB/PKCS5Padding&amp;quot;);&lt;br /&gt;
    cipher.init(Cipher.DECRYPT_MODE, key);&lt;br /&gt;
    CipherInputStream in = new CipherInputStream(new BufferedInputStream(new FileInputStream(f1)),&lt;br /&gt;
        cipher);&lt;br /&gt;
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f2));&lt;br /&gt;
    int i;&lt;br /&gt;
    do {&lt;br /&gt;
      i = in.read();&lt;br /&gt;
      if (i != -1)&lt;br /&gt;
        out.write(i);&lt;br /&gt;
    } while (i &amp;gt; 0);&lt;br /&gt;
    in.close();&lt;br /&gt;
    out.close();&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>