<?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_Tutorial%2FSecurity%2FSecretKey</id>
		<title>Java Tutorial/Security/SecretKey - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FSecurity%2FSecretKey"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Security/SecretKey&amp;action=history"/>
		<updated>2026-04-21T12:10:20Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java_Tutorial/Security/SecretKey&amp;diff=4320&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Security/SecretKey&amp;diff=4320&amp;oldid=prev"/>
				<updated>2010-06-01T05:01:36Z</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://www.jexp.ru/index.php?title=Java_Tutorial/Security/SecretKey&amp;diff=4319&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java_Tutorial/Security/SecretKey&amp;diff=4319&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;==  Create a 192 bit secret key from raw bytes ==&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 javax.crypto.Cipher;&lt;br /&gt;
import javax.crypto.SecretKey;&lt;br /&gt;
import javax.crypto.spec.SecretKeySpec;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    byte[] data = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };&lt;br /&gt;
    Cipher c = Cipher.getInstance(&amp;quot;Blowfish/ECB/NoPadding&amp;quot;);&lt;br /&gt;
    SecretKey key192 = new SecretKeySpec(new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,&lt;br /&gt;
        0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,&lt;br /&gt;
        0x16, 0x17 }, &amp;quot;Blowfish&amp;quot;);&lt;br /&gt;
    c.init(Cipher.ENCRYPT_MODE, key192);&lt;br /&gt;
    c.doFinal(data);&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;
==  Create a 64 bit secret key from raw bytes ==&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 javax.crypto.Cipher;&lt;br /&gt;
import javax.crypto.SecretKey;&lt;br /&gt;
import javax.crypto.spec.SecretKeySpec;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    byte[] data = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 };&lt;br /&gt;
    SecretKey key64 = new SecretKeySpec(&lt;br /&gt;
        new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }, &amp;quot;Blowfish&amp;quot;);&lt;br /&gt;
    Cipher c = Cipher.getInstance(&amp;quot;Blowfish/ECB/NoPadding&amp;quot;);&lt;br /&gt;
    c.init(Cipher.ENCRYPT_MODE, key64);&lt;br /&gt;
    c.doFinal(data);&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;
==  Create SecretKey ==&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.security.Key;&lt;br /&gt;
import javax.crypto.Cipher;&lt;br /&gt;
import javax.crypto.KeyGenerator;&lt;br /&gt;
import javax.crypto.SecretKey;&lt;br /&gt;
import javax.crypto.SecretKeyFactory;&lt;br /&gt;
import javax.crypto.spec.PBEKeySpec;&lt;br /&gt;
import javax.crypto.spec.PBEParameterSpec;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    KeyGenerator kg = KeyGenerator.getInstance(&amp;quot;DESede&amp;quot;);&lt;br /&gt;
    Key sharedKey = kg.generateKey();&lt;br /&gt;
    String password = &amp;quot;password&amp;quot;;&lt;br /&gt;
    byte[] salt = &amp;quot;salt1234&amp;quot;.getBytes();&lt;br /&gt;
    PBEParameterSpec paramSpec = new PBEParameterSpec(salt, 20);&lt;br /&gt;
    PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray());&lt;br /&gt;
    SecretKeyFactory kf = SecretKeyFactory.getInstance(&amp;quot;PBEWithMD5AndDES&amp;quot;);&lt;br /&gt;
    SecretKey passwordKey = kf.generateSecret(keySpec);&lt;br /&gt;
    Cipher c = Cipher.getInstance(&amp;quot;PBEWithMD5AndDES&amp;quot;);&lt;br /&gt;
    c.init(Cipher.WRAP_MODE, passwordKey, paramSpec);&lt;br /&gt;
    byte[] wrappedKey = c.wrap(sharedKey);&lt;br /&gt;
    c = Cipher.getInstance(&amp;quot;DESede&amp;quot;);&lt;br /&gt;
    c.init(Cipher.ENCRYPT_MODE, sharedKey);&lt;br /&gt;
    byte[] input = &amp;quot;input&amp;quot;.getBytes();&lt;br /&gt;
    byte[] encrypted = c.doFinal(input);&lt;br /&gt;
    c = Cipher.getInstance(&amp;quot;PBEWithMD5AndDES&amp;quot;);&lt;br /&gt;
    c.init(Cipher.UNWRAP_MODE, passwordKey, paramSpec);&lt;br /&gt;
    Key unwrappedKey = c.unwrap(wrappedKey, &amp;quot;DESede&amp;quot;, Cipher.SECRET_KEY);&lt;br /&gt;
    c = Cipher.getInstance(&amp;quot;DESede&amp;quot;);&lt;br /&gt;
    c.init(Cipher.DECRYPT_MODE, unwrappedKey);&lt;br /&gt;
    System.out.println(new String(c.doFinal(encrypted)));&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;
==  implements SecretKey ==&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 javax.crypto.SecretKey;&lt;br /&gt;
public class XORKey implements SecretKey {&lt;br /&gt;
  int rotValue;&lt;br /&gt;
  XORKey(int value) {&lt;br /&gt;
    rotValue = value;&lt;br /&gt;
  }&lt;br /&gt;
  public String getAlgorithm() {&lt;br /&gt;
    return &amp;quot;XOR&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
  public String getFormat() {&lt;br /&gt;
    return &amp;quot;XOR Special Format&amp;quot;;&lt;br /&gt;
  }&lt;br /&gt;
  public byte[] getEncoded() {&lt;br /&gt;
    byte b[] = new byte[4];&lt;br /&gt;
    b[3] = (byte) ((rotValue &amp;lt;&amp;lt; 24) &amp;amp; 0xff);&lt;br /&gt;
    b[2] = (byte) ((rotValue &amp;lt;&amp;lt; 16) &amp;amp; 0xff);&lt;br /&gt;
    b[1] = (byte) ((rotValue &amp;lt;&amp;lt; 8) &amp;amp; 0xff);&lt;br /&gt;
    b[0] = (byte) ((rotValue &amp;lt;&amp;lt; 0) &amp;amp; 0xff);&lt;br /&gt;
    return b;&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>