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

	<entry>
		<id>http://jexp.ru/index.php?title=Java_Tutorial/Security/RSA_algorithm&amp;diff=4328&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/Security/RSA_algorithm&amp;diff=4328&amp;oldid=prev"/>
				<updated>2010-06-01T05:01:40Z</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/RSA_algorithm&amp;diff=4327&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/RSA_algorithm&amp;diff=4327&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;==  An example of using RSA to encrypt a single asymmetric key. ==&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 java.security.KeyPair;&lt;br /&gt;
import java.security.KeyPairGenerator;&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.spec.SecretKeySpec;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    KeyGenerator keyGenerator = KeyGenerator.getInstance(&amp;quot;Blowfish&amp;quot;);&lt;br /&gt;
    keyGenerator.init(128);&lt;br /&gt;
    Key blowfishKey = keyGenerator.generateKey();&lt;br /&gt;
    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(&amp;quot;RSA&amp;quot;);&lt;br /&gt;
    keyPairGenerator.initialize(1024);&lt;br /&gt;
    KeyPair keyPair = keyPairGenerator.genKeyPair();&lt;br /&gt;
    Cipher cipher = Cipher.getInstance(&amp;quot;RSA/ECB/PKCS1Padding&amp;quot;);&lt;br /&gt;
    cipher.init(Cipher.ENCRYPT_MODE, keyPair.getPublic());&lt;br /&gt;
    byte[] blowfishKeyBytes = blowfishKey.getEncoded();&lt;br /&gt;
    System.out.println(new String(blowfishKeyBytes));&lt;br /&gt;
    byte[] cipherText = cipher.doFinal(blowfishKeyBytes);&lt;br /&gt;
    System.out.println(new String(cipherText));&lt;br /&gt;
    cipher.init(Cipher.DECRYPT_MODE, keyPair.getPrivate());&lt;br /&gt;
    byte[] decryptedKeyBytes = cipher.doFinal(cipherText);&lt;br /&gt;
    System.out.println(new String(decryptedKeyBytes));&lt;br /&gt;
    SecretKey newBlowfishKey = new SecretKeySpec(decryptedKeyBytes, &amp;quot;Blowfish&amp;quot;);&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;
==  An RSA sample application ==&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.math.BigInteger;&lt;br /&gt;
import java.security.KeyFactory;&lt;br /&gt;
import java.security.KeyPair;&lt;br /&gt;
import java.security.KeyPairGenerator;&lt;br /&gt;
import java.security.spec.RSAKeyGenParameterSpec;&lt;br /&gt;
import java.security.spec.RSAPublicKeySpec;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    int eValue = 79;&lt;br /&gt;
    int bitLength = 1024; // KeySize&lt;br /&gt;
    BigInteger e = e = new BigInteger(Integer.toString(eValue));&lt;br /&gt;
    KeyPairGenerator kpg = KeyPairGenerator.getInstance(&amp;quot;RSA&amp;quot;);&lt;br /&gt;
    kpg.initialize(bitLength);&lt;br /&gt;
    KeyPair kp = kpg.generateKeyPair();&lt;br /&gt;
    KeyFactory kfactory = KeyFactory.getInstance(&amp;quot;RSA&amp;quot;);&lt;br /&gt;
    RSAPublicKeySpec kspec = (RSAPublicKeySpec) kfactory.getKeySpec(kp.getPublic(),&lt;br /&gt;
        RSAPublicKeySpec.class);&lt;br /&gt;
    kpg = KeyPairGenerator.getInstance(&amp;quot;RSA&amp;quot;, &amp;quot;SunRsaSign&amp;quot;);&lt;br /&gt;
    e = new BigInteger(Integer.toString(eValue));&lt;br /&gt;
    System.out.println(&amp;quot;e =&amp;quot; + e);&lt;br /&gt;
    RSAKeyGenParameterSpec param = new RSAKeyGenParameterSpec(bitLength, e);&lt;br /&gt;
    kpg.initialize(param);&lt;br /&gt;
    kp = kpg.generateKeyPair();&lt;br /&gt;
    kfactory = KeyFactory.getInstance(&amp;quot;RSA&amp;quot;, &amp;quot;SunRsaSign&amp;quot;);&lt;br /&gt;
    kspec = (RSAPublicKeySpec) kfactory.getKeySpec(kp.getPublic(),RSAPublicKeySpec.class);&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;
==  Basic RSA example. ==&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.math.BigInteger;&lt;br /&gt;
import java.security.KeyFactory;&lt;br /&gt;
import java.security.Security;&lt;br /&gt;
import java.security.interfaces.RSAPrivateKey;&lt;br /&gt;
import java.security.interfaces.RSAPublicKey;&lt;br /&gt;
import java.security.spec.RSAPrivateKeySpec;&lt;br /&gt;
import java.security.spec.RSAPublicKeySpec;&lt;br /&gt;
import javax.crypto.Cipher;&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 = new byte[] { (byte) 0xbe, (byte) 0xef };&lt;br /&gt;
    Cipher cipher = Cipher.getInstance(&amp;quot;RSA/None/NoPadding&amp;quot;, &amp;quot;BC&amp;quot;);&lt;br /&gt;
    KeyFactory keyFactory = KeyFactory.getInstance(&amp;quot;RSA&amp;quot;, &amp;quot;BC&amp;quot;);&lt;br /&gt;
    RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(new BigInteger(&lt;br /&gt;
        &amp;quot;12345678&amp;quot;, 16), new BigInteger(&amp;quot;11&amp;quot;, 16));&lt;br /&gt;
    RSAPrivateKeySpec privKeySpec = new RSAPrivateKeySpec(new BigInteger(&lt;br /&gt;
        &amp;quot;12345678&amp;quot;, 16), new BigInteger(&amp;quot;12345678&amp;quot;,&lt;br /&gt;
        16));&lt;br /&gt;
    RSAPublicKey pubKey = (RSAPublicKey) keyFactory.generatePublic(pubKeySpec);&lt;br /&gt;
    RSAPrivateKey privKey = (RSAPrivateKey) keyFactory.generatePrivate(privKeySpec);&lt;br /&gt;
    cipher.init(Cipher.ENCRYPT_MODE, pubKey);&lt;br /&gt;
    byte[] cipherText = cipher.doFinal(input);&lt;br /&gt;
    System.out.println(&amp;quot;cipher: &amp;quot; + new String(cipherText));&lt;br /&gt;
    cipher.init(Cipher.DECRYPT_MODE, privKey);&lt;br /&gt;
    byte[] plainText = cipher.doFinal(cipherText);&lt;br /&gt;
    System.out.println(&amp;quot;plain : &amp;quot; + new String(plainText));&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;
==  Creates a it RSA key pair and stores it to the filesystem as two files ==&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.ByteArrayOutputStream;&lt;br /&gt;
import java.io.FileOutputStream;&lt;br /&gt;
import java.security.KeyPair;&lt;br /&gt;
import java.security.KeyPairGenerator;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import javax.crypto.Cipher;&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;
    String password = &amp;quot;password&amp;quot;;&lt;br /&gt;
    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(&amp;quot;RSA&amp;quot;);&lt;br /&gt;
    keyPairGenerator.initialize(1024);&lt;br /&gt;
    KeyPair keyPair = keyPairGenerator.genKeyPair();&lt;br /&gt;
    String publicKeyFilename = &amp;quot;public&amp;quot;;&lt;br /&gt;
    byte[] publicKeyBytes = keyPair.getPublic().getEncoded();&lt;br /&gt;
    FileOutputStream fos = new FileOutputStream(publicKeyFilename);&lt;br /&gt;
    fos.write(publicKeyBytes);&lt;br /&gt;
    fos.close();&lt;br /&gt;
    String privateKeyFilename = &amp;quot;privateKeyFilename&amp;quot;;&lt;br /&gt;
    byte[] privateKeyBytes = keyPair.getPrivate().getEncoded();&lt;br /&gt;
    byte[] encryptedPrivateKeyBytes = passwordEncrypt(password.toCharArray(), privateKeyBytes);&lt;br /&gt;
    fos = new FileOutputStream(privateKeyFilename);&lt;br /&gt;
    fos.write(encryptedPrivateKeyBytes);&lt;br /&gt;
    fos.close();&lt;br /&gt;
  }&lt;br /&gt;
  private static byte[] passwordEncrypt(char[] password, byte[] plaintext) throws Exception {&lt;br /&gt;
    int MD5_ITERATIONS = 1000;&lt;br /&gt;
    byte[] salt = new byte[8];&lt;br /&gt;
    SecureRandom random = new SecureRandom();&lt;br /&gt;
    random.nextBytes(salt);&lt;br /&gt;
    PBEKeySpec keySpec = new PBEKeySpec(password);&lt;br /&gt;
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(&amp;quot;PBEWithSHAAndTwofish-CBC&amp;quot;);&lt;br /&gt;
    SecretKey key = keyFactory.generateSecret(keySpec);&lt;br /&gt;
    PBEParameterSpec paramSpec = new PBEParameterSpec(salt, MD5_ITERATIONS);&lt;br /&gt;
    Cipher cipher = Cipher.getInstance(&amp;quot;PBEWithSHAAndTwofish-CBC&amp;quot;);&lt;br /&gt;
    cipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);&lt;br /&gt;
    byte[] ciphertext = cipher.doFinal(plaintext);&lt;br /&gt;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();&lt;br /&gt;
    baos.write(salt);&lt;br /&gt;
    baos.write(ciphertext);&lt;br /&gt;
    return baos.toByteArray();&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;
==  RSA example with OAEP Padding and random key generation. ==&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 java.security.KeyPair;&lt;br /&gt;
import java.security.KeyPairGenerator;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.security.Security;&lt;br /&gt;
import javax.crypto.Cipher;&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;abc&amp;quot;.getBytes();&lt;br /&gt;
    Cipher cipher = Cipher.getInstance(&amp;quot;RSA/None/OAEPWithSHA1AndMGF1Padding&amp;quot;, &amp;quot;BC&amp;quot;);&lt;br /&gt;
    SecureRandom random = new SecureRandom();&lt;br /&gt;
    KeyPairGenerator generator = KeyPairGenerator.getInstance(&amp;quot;RSA&amp;quot;, &amp;quot;BC&amp;quot;);&lt;br /&gt;
    generator.initialize(386, random);&lt;br /&gt;
    KeyPair pair = generator.generateKeyPair();&lt;br /&gt;
    Key pubKey = pair.getPublic();&lt;br /&gt;
    Key privKey = pair.getPrivate();&lt;br /&gt;
    cipher.init(Cipher.ENCRYPT_MODE, pubKey, random);&lt;br /&gt;
    byte[] cipherText = cipher.doFinal(input);&lt;br /&gt;
    System.out.println(&amp;quot;cipher: &amp;quot; + new String(cipherText));&lt;br /&gt;
    cipher.init(Cipher.DECRYPT_MODE, privKey);&lt;br /&gt;
    byte[] plainText = cipher.doFinal(cipherText);&lt;br /&gt;
    System.out.println(&amp;quot;plain : &amp;quot; + new String(plainText));&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;
==  RSA example with PKCS #1 Padding. ==&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 java.security.KeyPair;&lt;br /&gt;
import java.security.KeyPairGenerator;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.security.Security;&lt;br /&gt;
import javax.crypto.Cipher;&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;abc&amp;quot;.getBytes();&lt;br /&gt;
    Cipher cipher = Cipher.getInstance(&amp;quot;RSA/None/PKCS1Padding&amp;quot;, &amp;quot;BC&amp;quot;);&lt;br /&gt;
    SecureRandom random = new SecureRandom();&lt;br /&gt;
    KeyPairGenerator generator = KeyPairGenerator.getInstance(&amp;quot;RSA&amp;quot;, &amp;quot;BC&amp;quot;);&lt;br /&gt;
    generator.initialize(256, random);&lt;br /&gt;
    KeyPair pair = generator.generateKeyPair();&lt;br /&gt;
    Key pubKey = pair.getPublic();&lt;br /&gt;
    Key privKey = pair.getPrivate();&lt;br /&gt;
    cipher.init(Cipher.ENCRYPT_MODE, pubKey, random);&lt;br /&gt;
    byte[] cipherText = cipher.doFinal(input);&lt;br /&gt;
    System.out.println(&amp;quot;cipher: &amp;quot; + new String(cipherText));&lt;br /&gt;
    cipher.init(Cipher.DECRYPT_MODE, privKey);&lt;br /&gt;
    byte[] plainText = cipher.doFinal(cipherText);&lt;br /&gt;
    System.out.println(&amp;quot;plain : &amp;quot; + new String(plainText));&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;
==  RSA example with random key generation. ==&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 java.security.KeyPair;&lt;br /&gt;
import java.security.KeyPairGenerator;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.security.Security;&lt;br /&gt;
import javax.crypto.Cipher;&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;aa&amp;quot;.getBytes();&lt;br /&gt;
    Cipher cipher = Cipher.getInstance(&amp;quot;RSA/None/NoPadding&amp;quot;, &amp;quot;BC&amp;quot;);&lt;br /&gt;
    SecureRandom random = new SecureRandom();&lt;br /&gt;
    KeyPairGenerator generator = KeyPairGenerator.getInstance(&amp;quot;RSA&amp;quot;, &amp;quot;BC&amp;quot;);&lt;br /&gt;
    generator.initialize(256, random);&lt;br /&gt;
    KeyPair pair = generator.generateKeyPair();&lt;br /&gt;
    Key pubKey = pair.getPublic();&lt;br /&gt;
    Key privKey = pair.getPrivate();&lt;br /&gt;
    cipher.init(Cipher.ENCRYPT_MODE, pubKey, random);&lt;br /&gt;
    byte[] cipherText = cipher.doFinal(input);&lt;br /&gt;
    System.out.println(&amp;quot;cipher: &amp;quot; + new String(cipherText));&lt;br /&gt;
    cipher.init(Cipher.DECRYPT_MODE, privKey);&lt;br /&gt;
    byte[] plainText = cipher.doFinal(cipherText);&lt;br /&gt;
    System.out.println(&amp;quot;plain : &amp;quot; + new String(plainText));&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;
==  RSA Signature Generation ==&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.KeyPair;&lt;br /&gt;
import java.security.KeyPairGenerator;&lt;br /&gt;
import java.security.SecureRandom;&lt;br /&gt;
import java.security.Security;&lt;br /&gt;
import java.security.Signature;&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;
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance(&amp;quot;RSA&amp;quot;, &amp;quot;BC&amp;quot;);&lt;br /&gt;
    keyGen.initialize(512, new SecureRandom());&lt;br /&gt;
    KeyPair keyPair = keyGen.generateKeyPair();&lt;br /&gt;
    Signature signature = Signature.getInstance(&amp;quot;SHA1withRSA&amp;quot;, &amp;quot;BC&amp;quot;);&lt;br /&gt;
    signature.initSign(keyPair.getPrivate(), new SecureRandom());&lt;br /&gt;
    byte[] message = &amp;quot;abc&amp;quot;.getBytes();&lt;br /&gt;
    signature.update(message);&lt;br /&gt;
    byte[] sigBytes = signature.sign();&lt;br /&gt;
    signature.initVerify(keyPair.getPublic());&lt;br /&gt;
    signature.update(message);&lt;br /&gt;
    System.out.println(signature.verify(sigBytes));&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;
==  Simple Digital Signature Example ==&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.KeyPair;&lt;br /&gt;
import java.security.KeyPairGenerator;&lt;br /&gt;
import java.security.Signature;&lt;br /&gt;
import sun.misc.BASE64Encoder;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) throws Exception {&lt;br /&gt;
    KeyPairGenerator kpg = KeyPairGenerator.getInstance(&amp;quot;RSA&amp;quot;);&lt;br /&gt;
    kpg.initialize(1024);&lt;br /&gt;
    KeyPair keyPair = kpg.genKeyPair();&lt;br /&gt;
    byte[] data = &amp;quot;test&amp;quot;.getBytes(&amp;quot;UTF8&amp;quot;);&lt;br /&gt;
    Signature sig = Signature.getInstance(&amp;quot;MD5WithRSA&amp;quot;);&lt;br /&gt;
    sig.initSign(keyPair.getPrivate());&lt;br /&gt;
    sig.update(data);&lt;br /&gt;
    byte[] signatureBytes = sig.sign();&lt;br /&gt;
    System.out.println(&amp;quot;Singature:&amp;quot; + new BASE64Encoder().encode(signatureBytes));&lt;br /&gt;
    sig.initVerify(keyPair.getPublic());&lt;br /&gt;
    sig.update(data);&lt;br /&gt;
    System.out.println(sig.verify(signatureBytes));&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>