Difference between revisions of "Uso de las Extensiones Criptográficas de Java"

From OWASP
Jump to: navigation, search
(version inicial)
 
(Adición de ejemplos de código)
 
Line 53: Line 53:
 
# SHA1 - por defecto 64 bytes de tamaño
 
# SHA1 - por defecto 64 bytes de tamaño
  
==TRADUCIDO POR ABALCO DAVID Y CASTRO WILSON==
+
==Ejemplos==
 +
===SecureRandom===
 +
La calse SecureRandom esa usada para generar pseudo números criptográficamente aleatorios al usar el algoritmo PRNG.
 +
 
 +
Las siguientes son las ventajas de utilizar SecureRandom en ves de Random:
 +
1. SecureRandom produce un generador de números aleatorios criptográficamente fuerte.
 +
2. SecureRandom produce secuencias critográficamente fuertes como se describe en las
 +
[http://www.ietf.org/rfc/rfc1750.txt RFC 1750: Recomendaciones de aleatoriedad para seguridad (En inglés)]
 +
 
 +
<pre>
 +
package org.owasp.java.crypto;
 +
 
 +
import java.security.SecureRandom;
 +
import java.security.NoSuchAlgorithmException;
 +
 
 +
import sun.misc.BASE64Encoder;
 +
 
 +
/**
 +
* @author Joe Prasanna Kumar
 +
* This program provides the functionality for Generating a Secure Random Number.
 +
 +
* There are 2 ways to generate a  Random number through SecureRandom.
 +
* 1. By calling nextBytes method to generate Random Bytes
 +
* 2. Using setSeed(byte[]) to reseed a Random object
 +
*
 +
*/
 +
 
 +
 
 +
public class SecureRandomGen {
 +
 
 +
/**
 +
* @param args
 +
*/
 +
public static void main(String[] args) {
 +
try {
 +
        // Initialize a secure random number generator
 +
        SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
 +
   
 +
        // Method 1 - Calling nextBytes method to generate Random Bytes
 +
        byte[] bytes = new byte[512];
 +
        secureRandom.nextBytes(bytes);
 +
       
 +
        // Printing the SecureRandom number by calling secureRandom.nextDouble()
 +
        System.out.println(" Secure Random # generated by calling nextBytes() is " + secureRandom.nextDouble());
 +
   
 +
        // Method 2 - Using setSeed(byte[]) to reseed a Random object
 +
        int seedByteCount = 10;
 +
        byte[] seed = secureRandom.generateSeed(seedByteCount); 
 +
       
 +
        // TBR System.out.println(" Seed value is " + new BASE64Encoder().encode(seed));
 +
   
 +
        secureRandom.setSeed(seed);
 +
       
 +
        System.out.println(" Secure Random # generated using setSeed(byte[]) is  " + secureRandom.nextDouble());
 +
       
 +
    } catch (NoSuchAlgorithmException noSuchAlgo)
 +
{
 +
System.out.println(" No Such Algorithm exists " + noSuchAlgo);
 +
}
 +
}
 +
 
 +
}
 +
</pre>
 +
 
 +
=== Cifrado y Decifrado AES ===
 +
<pre>
 +
package org.owasp.java.crypto;
 +
 
 +
import javax.crypto.KeyGenerator;
 +
import javax.crypto.SecretKey;
 +
import javax.crypto.Cipher;
 +
 
 +
import java.security.NoSuchAlgorithmException;
 +
import java.security.InvalidKeyException;
 +
import java.security.InvalidAlgorithmParameterException;
 +
import javax.crypto.NoSuchPaddingException;
 +
import javax.crypto.BadPaddingException;
 +
import javax.crypto.IllegalBlockSizeException;
 +
 
 +
import sun.misc.BASE64Encoder;
 +
 
 +
/**
 +
* @author Joe Prasanna Kumar
 +
* This program provides the following cryptographic functionalities
 +
* 1. Encryption using AES
 +
* 2. Decryption using AES
 +
*
 +
* High Level Algorithm :
 +
* 1. Generate a DES key (specify the Key size during this phase)
 +
* 2. Create the Cipher
 +
* 3. To Encrypt : Initialize the Cipher for Encryption
 +
* 4. To Decrypt : Initialize the Cipher for Decryption
 +
*
 +
*
 +
*/
 +
 
 +
public class AES {
 +
public static void main(String[] args) {
 +
 +
String strDataToEncrypt = new String();
 +
String strCipherText = new String();
 +
String strDecryptedText = new String();
 +
 +
try{
 +
/**
 +
*  Step 1. Generate an AES key using KeyGenerator
 +
*  Initialize the keysize to 128
 +
*
 +
*/
 +
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
 +
keyGen.init(128);
 +
SecretKey secretKey = keyGen.generateKey();
 +
 +
/**
 +
*  Step2. Create a Cipher by specifying the following parameters
 +
* a. Algorithm name - here it is AES
 +
*/
 +
 +
Cipher aesCipher = Cipher.getInstance("AES");
 +
 +
/**
 +
*  Step 3. Initialize the Cipher for Encryption
 +
*/
 +
 +
aesCipher.init(Cipher.ENCRYPT_MODE,secretKey);
 +
 +
/**
 +
*  Step 4. Encrypt the Data
 +
*  1. Declare / Initialize the Data. Here the data is of type String
 +
*  2. Convert the Input Text to Bytes
 +
*  3. Encrypt the bytes using doFinal method
 +
*/
 +
strDataToEncrypt = "Hello World of Encryption using AES ";
 +
byte[] byteDataToEncrypt = strDataToEncrypt.getBytes();
 +
byte[] byteCipherText = aesCipher.doFinal(byteDataToEncrypt);
 +
strCipherText = new BASE64Encoder().encode(byteCipherText);
 +
System.out.println("Cipher Text generated using AES is " +strCipherText);
 +
 +
/**
 +
*  Step 5. Decrypt the Data
 +
*  1. Initialize the Cipher for Decryption
 +
*  2. Decrypt the cipher bytes using doFinal method
 +
*/
 +
aesCipher.init(Cipher.DECRYPT_MODE,secretKey,aesCipher.getParameters());
 +
byte[] byteDecryptedText = aesCipher.doFinal(byteCipherText);
 +
strDecryptedText = new String(byteDecryptedText);
 +
System.out.println(" Decrypted Text message is " +strDecryptedText);
 +
}
 +
 +
catch (NoSuchAlgorithmException noSuchAlgo)
 +
{
 +
System.out.println(" No Such Algorithm exists " + noSuchAlgo);
 +
}
 +
 +
catch (NoSuchPaddingException noSuchPad)
 +
{
 +
System.out.println(" No Such Padding exists " + noSuchPad);
 +
}
 +
 +
catch (InvalidKeyException invalidKey)
 +
{
 +
System.out.println(" Invalid Key " + invalidKey);
 +
}
 +
 +
catch (BadPaddingException badPadding)
 +
{
 +
System.out.println(" Bad Padding " + badPadding);
 +
}
 +
 +
catch (IllegalBlockSizeException illegalBlockSize)
 +
{
 +
System.out.println(" Illegal Block Size " + illegalBlockSize);
 +
}
 +
 +
catch (InvalidAlgorithmParameterException invalidParam)
 +
{
 +
System.out.println(" Invalid Parameter " + invalidParam);
 +
}
 +
}
 +
 
 +
}
 +
</pre>
 +
=== Cifrado y Decifrado DES ===
 +
<pre>
 +
package org.owasp.crypto;
 +
 
 +
import javax.crypto.KeyGenerator;
 +
import javax.crypto.SecretKey;
 +
import javax.crypto.Cipher;
 +
 
 +
import java.security.NoSuchAlgorithmException;
 +
import java.security.InvalidKeyException;
 +
import java.security.InvalidAlgorithmParameterException;
 +
import javax.crypto.NoSuchPaddingException;
 +
import javax.crypto.BadPaddingException;
 +
import javax.crypto.IllegalBlockSizeException;
 +
 
 +
import sun.misc.BASE64Encoder;
 +
 
 +
/**
 +
* @author Joe Prasanna Kumar
 +
* This program provides the following cryptographic functionalities
 +
* 1. Encryption using DES
 +
* 2. Decryption using DES
 +
*
 +
* The following modes of DES encryption are supported by SUNJce provider
 +
* 1. ECB (Electronic code Book) - Every plaintext block is encrypted separately
 +
* 2. CBC (Cipher Block Chaining) - Every plaintext block is XORed with the previous ciphertext block
 +
* 3. PCBC (Propogating Cipher Block Chaining) -
 +
* 4. CFB (Cipher Feedback Mode) - The previous ciphertext block is encrypted and this enciphered block is XORed with the plaintext block to produce the corresponding ciphertext block
 +
* 5. OFB (Output Feedback Mode) -
 +
*
 +
* High Level Algorithm :
 +
* 1. Generate a DES key
 +
* 2. Create the Cipher (Specify the Mode and Padding)
 +
* 3. To Encrypt : Initialize the Cipher for Encryption
 +
* 4. To Decrypt : Initialize the Cipher for Decryption
 +
*
 +
* Need for Padding :
 +
* Block ciphers operates on data blocks on fixed size n.
 +
* Since the data to be encrypted might not always be a multiple of n, the remainder of the bits are padded.
 +
* PKCS#5 Padding is what will be used in this program
 +
*
 +
*/
 +
 
 +
public class DES {
 +
public static void main(String[] args) {
 +
 +
String strDataToEncrypt = new String();
 +
String strCipherText = new String();
 +
String strDecryptedText = new String();
 +
 +
try{
 +
/**
 +
*  Step 1. Generate a DES key using KeyGenerator
 +
*
 +
*/
 +
KeyGenerator keyGen = KeyGenerator.getInstance("DES");
 +
SecretKey secretKey = keyGen.generateKey();
 +
 +
/**
 +
*  Step2. Create a Cipher by specifying the following parameters
 +
* a. Algorithm name - here it is DES
 +
* b. Mode - here it is CBC
 +
* c. Padding - PKCS5Padding
 +
*/
 +
 +
Cipher desCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
 +
 +
/**
 +
*  Step 3. Initialize the Cipher for Encryption
 +
*/
 +
 +
desCipher.init(Cipher.ENCRYPT_MODE,secretKey);
 +
 +
/**
 +
*  Step 4. Encrypt the Data
 +
*  1. Declare / Initialize the Data. Here the data is of type String
 +
*  2. Convert the Input Text to Bytes
 +
*  3. Encrypt the bytes using doFinal method
 +
*/
 +
strDataToEncrypt = "Hello World of Encryption using DES ";
 +
byte[] byteDataToEncrypt = strDataToEncrypt.getBytes();
 +
byte[] byteCipherText = desCipher.doFinal(byteDataToEncrypt);
 +
strCipherText = new BASE64Encoder().encode(byteCipherText);
 +
System.out.println("Cipher Text generated using DES with CBC mode and PKCS5 Padding is " +strCipherText);
 +
 +
/**
 +
*  Step 5. Decrypt the Data
 +
*  1. Initialize the Cipher for Decryption
 +
*  2. Decrypt the cipher bytes using doFinal method
 +
*/
 +
desCipher.init(Cipher.DECRYPT_MODE,secretKey,desCipher.getParameters());
 +
//desCipher.init(Cipher.DECRYPT_MODE,secretKey);
 +
byte[] byteDecryptedText = desCipher.doFinal(byteCipherText);
 +
strDecryptedText = new String(byteDecryptedText);
 +
System.out.println(" Decrypted Text message is " +strDecryptedText);
 +
}
 +
 +
catch (NoSuchAlgorithmException noSuchAlgo)
 +
{
 +
System.out.println(" No Such Algorithm exists " + noSuchAlgo);
 +
}
 +
 +
catch (NoSuchPaddingException noSuchPad)
 +
{
 +
System.out.println(" No Such Padding exists " + noSuchPad);
 +
}
 +
 +
catch (InvalidKeyException invalidKey)
 +
{
 +
System.out.println(" Invalid Key " + invalidKey);
 +
}
 +
 +
catch (BadPaddingException badPadding)
 +
{
 +
System.out.println(" Bad Padding " + badPadding);
 +
}
 +
 +
catch (IllegalBlockSizeException illegalBlockSize)
 +
{
 +
System.out.println(" Illegal Block Size " + illegalBlockSize);
 +
}
 +
 +
catch (InvalidAlgorithmParameterException invalidParam)
 +
{
 +
System.out.println(" Invalid Parameter " + invalidParam);
 +
}
 +
}
 +
 
 +
}
 +
</pre>
 +
 
 +
 
 +
==Detalles de Traducción==
 +
#POR ABALCO DAVID Y CASTRO WILSON
 
#ESCUELA POLITÉCNICA NACIONAL
 
#ESCUELA POLITÉCNICA NACIONAL
 
#APLICACIONES EN AMBIENTES LIBRES
 
#APLICACIONES EN AMBIENTES LIBRES
Line 59: Line 374:
 
#15/11/2012
 
#15/11/2012
 
#QUITO-ECUADOR
 
#QUITO-ECUADOR
 +
#Con la colaboración de Juan Carlos Calderón (Ejemplos de código)

Latest revision as of 23:13, 15 September 2013

Contents

Contenido

  1. Nota:
  2. Descripción general
    1. Algoritmos de cifrado simétrico proporcionados por SunJCE
    2. Modos de cifrado
    3. Algoritmos de cifrado asimétricos implementadas por SunJCE
    4. hashing / Message Digest algoritmos implementados por SunJCE
  3. Ejemplos
    1. Seguridad Randómica
    2. AES de cifrado y descifrado
    3. DES cifrado y descifrado

Nota:

El código incluido en este artículo no ha sido revisado y no se debe utilizar sin un análisis adecuado. Si ha revisado el código incluido (o partes de ellos), por favor enviar sus conclusiones a esta página o a: stephen [at] corsaire.com.

Descripción General

Extensiones Criptográficas Java (JCE) es un conjunto de API’s de Java, que proporciona servicios criptográficos como el cifrado, la generación de claves secretas, código de autenticación de mensajes y el Acuerdo clave. Los sistemas de cifrado soportados por JCE incluyen simetría, asimetría, bloque y cifrado de flujos. JCE fue un paquete opcional para JDK v 1.2.x y 1.3.x. JCE ha sido integrado en JDK v1.4.

JCE API’s se implementan los proveedores de servicios criptográficos. Cada uno de estos proveedores de servicios criptográficos implementa la interfaz del proveedor de servicio que especifican las funcionalidades que deben ser implementadas por los proveedores de servicios. Los programadores pueden obtener los plugin de cualquier proveedor de servicios para la realización de funcionalidades criptográficas proporcionadas por JCE. J2SE viene con un proveedor predeterminado, llamado SunJCE.

Algoritmos simétricos de cifrado proporcionadas por SunJCE

  1. DES - KeyLength predeterminado de 56 bits (longitud)
  2. AES
  3. RC2, RC4 y RC5
  4. IDEA
  5. Triple DES - KeyLength por defecto 112 bits
  6. Blowfish - KeyLength defecto 56 bits
  7. PBE con MD5 y DES
  8. PBE con HmacSHA1 y DESede
  9. DES ede

Modos de Encriptación

  1. BCE
  2. CBC
  3. CFB
  4. OFB
  5. PCBC

Algoritmos de cifrado asimétricos implementados por SunJCE

  1. RSA
  2. Diffie-Hellman - KeyLength defecto 1024 bits

Hashing / Message Digest algoritmos implementados por SunJCE

  1. MD5 - por defecto 64 bytes de tamaño
  2. SHA1 - por defecto 64 bytes de tamaño

Ejemplos

SecureRandom

La calse SecureRandom esa usada para generar pseudo números criptográficamente aleatorios al usar el algoritmo PRNG.

Las siguientes son las ventajas de utilizar SecureRandom en ves de Random: 1. SecureRandom produce un generador de números aleatorios criptográficamente fuerte. 2. SecureRandom produce secuencias critográficamente fuertes como se describe en las RFC 1750: Recomendaciones de aleatoriedad para seguridad (En inglés)

package org.owasp.java.crypto;

import java.security.SecureRandom;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Encoder;

/**
 * @author Joe Prasanna Kumar
 * This program provides the functionality for Generating a Secure Random Number.
 *  
 * There are 2 ways to generate a  Random number through SecureRandom.
 * 1. By calling nextBytes method to generate Random Bytes
 * 2. Using setSeed(byte[]) to reseed a Random object
 * 
 */


public class SecureRandomGen {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
	        // Initialize a secure random number generator
	        SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
	    
	        // Method 1 - Calling nextBytes method to generate Random Bytes
	        byte[] bytes = new byte[512];
	        secureRandom.nextBytes(bytes); 
	        
	        // Printing the SecureRandom number by calling secureRandom.nextDouble()
	        System.out.println(" Secure Random # generated by calling nextBytes() is " + secureRandom.nextDouble());
	    
	        // Method 2 - Using setSeed(byte[]) to reseed a Random object
	        int seedByteCount = 10;
	        byte[] seed = secureRandom.generateSeed(seedByteCount);   
	        
	        // TBR System.out.println(" Seed value is " + new BASE64Encoder().encode(seed));
	    
	        secureRandom.setSeed(seed);
	        
	        System.out.println(" Secure Random # generated using setSeed(byte[]) is  " + secureRandom.nextDouble());
	        
	    } catch (NoSuchAlgorithmException noSuchAlgo)
		{
			System.out.println(" No Such Algorithm exists " + noSuchAlgo);
		}
	}

}

Cifrado y Decifrado AES

package org.owasp.java.crypto;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.Cipher;

import java.security.NoSuchAlgorithmException;
import java.security.InvalidKeyException;
import java.security.InvalidAlgorithmParameterException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;

import sun.misc.BASE64Encoder;

/**
 * @author Joe Prasanna Kumar
 * This program provides the following cryptographic functionalities
 * 1. Encryption using AES
 * 2. Decryption using AES
 * 
 * High Level Algorithm :
 * 1. Generate a DES key (specify the Key size during this phase) 
 * 2. Create the Cipher 
 * 3. To Encrypt : Initialize the Cipher for Encryption
 * 4. To Decrypt : Initialize the Cipher for Decryption
 * 
 * 
 */

public class AES {
	public static void main(String[] args) {
		
		String strDataToEncrypt = new String();
		String strCipherText = new String();
		String strDecryptedText = new String();
		
		try{
		/**
		 *  Step 1. Generate an AES key using KeyGenerator
		 *  		Initialize the keysize to 128 
		 * 
		 */
		KeyGenerator keyGen = KeyGenerator.getInstance("AES");
		keyGen.init(128);
		SecretKey secretKey = keyGen.generateKey();
		
		/**
		 *  Step2. Create a Cipher by specifying the following parameters
		 * 			a. Algorithm name - here it is AES
		 */
		
		Cipher aesCipher = Cipher.getInstance("AES");
		
		/**
		 *  Step 3. Initialize the Cipher for Encryption 
		 */
		
		aesCipher.init(Cipher.ENCRYPT_MODE,secretKey);
		
		/**
		 *  Step 4. Encrypt the Data
		 *  		1. Declare / Initialize the Data. Here the data is of type String
		 *  		2. Convert the Input Text to Bytes
		 *  		3. Encrypt the bytes using doFinal method 
		 */
		strDataToEncrypt = "Hello World of Encryption using AES ";
		byte[] byteDataToEncrypt = strDataToEncrypt.getBytes();
		byte[] byteCipherText = aesCipher.doFinal(byteDataToEncrypt); 
		strCipherText = new BASE64Encoder().encode(byteCipherText);
		System.out.println("Cipher Text generated using AES is " +strCipherText);
		
		/**
		 *  Step 5. Decrypt the Data
		 *  		1. Initialize the Cipher for Decryption 
		 *  		2. Decrypt the cipher bytes using doFinal method 
		 */
		aesCipher.init(Cipher.DECRYPT_MODE,secretKey,aesCipher.getParameters());
		byte[] byteDecryptedText = aesCipher.doFinal(byteCipherText);
		strDecryptedText = new String(byteDecryptedText);
		System.out.println(" Decrypted Text message is " +strDecryptedText);
		}
		
		catch (NoSuchAlgorithmException noSuchAlgo)
		{
			System.out.println(" No Such Algorithm exists " + noSuchAlgo);
		}
		
			catch (NoSuchPaddingException noSuchPad)
			{
				System.out.println(" No Such Padding exists " + noSuchPad);
			}
		
				catch (InvalidKeyException invalidKey)
				{
					System.out.println(" Invalid Key " + invalidKey);
				}
				
				catch (BadPaddingException badPadding)
				{
					System.out.println(" Bad Padding " + badPadding);
				}
				
				catch (IllegalBlockSizeException illegalBlockSize)
				{
					System.out.println(" Illegal Block Size " + illegalBlockSize);
				}
				
				catch (InvalidAlgorithmParameterException invalidParam)
				{
					System.out.println(" Invalid Parameter " + invalidParam);
				}
	}

}

Cifrado y Decifrado DES

package org.owasp.crypto;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.Cipher;

import java.security.NoSuchAlgorithmException;
import java.security.InvalidKeyException;
import java.security.InvalidAlgorithmParameterException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;

import sun.misc.BASE64Encoder;

/**
 * @author Joe Prasanna Kumar
 * This program provides the following cryptographic functionalities
 * 1. Encryption using DES
 * 2. Decryption using DES
 * 
 * The following modes of DES encryption are supported by SUNJce provider 
 * 1. ECB (Electronic code Book) - Every plaintext block is encrypted separately 
 * 2. CBC (Cipher Block Chaining) - Every plaintext block is XORed with the previous ciphertext block
 * 3. PCBC (Propogating Cipher Block Chaining) - 
 * 4. CFB (Cipher Feedback Mode) - The previous ciphertext block is encrypted and this enciphered block is XORed with the plaintext block to produce the corresponding ciphertext block 
 * 5. OFB (Output Feedback Mode) - 
 *
 *	High Level Algorithm :
 * 1. Generate a DES key
 * 2. Create the Cipher (Specify the Mode and Padding)
 * 3. To Encrypt : Initialize the Cipher for Encryption
 * 4. To Decrypt : Initialize the Cipher for Decryption
 * 
 * Need for Padding :
 * Block ciphers operates on data blocks on fixed size n. 
 * Since the data to be encrypted might not always be a multiple of n, the remainder of the bits are padded.
 * PKCS#5 Padding is what will be used in this program 
 * 
 */

public class DES {
	public static void main(String[] args) {
		
		String strDataToEncrypt = new String();
		String strCipherText = new String();
		String strDecryptedText = new String();
		
		try{
		/**
		 *  Step 1. Generate a DES key using KeyGenerator 
		 * 
		 */
		KeyGenerator keyGen = KeyGenerator.getInstance("DES");
		SecretKey secretKey = keyGen.generateKey();
		
		/**
		 *  Step2. Create a Cipher by specifying the following parameters
		 * 			a. Algorithm name - here it is DES
		 * 			b. Mode - here it is CBC
		 * 			c. Padding - PKCS5Padding
		 */
		
		Cipher desCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
		
		/**
		 *  Step 3. Initialize the Cipher for Encryption 
		 */
		
		desCipher.init(Cipher.ENCRYPT_MODE,secretKey);
		
		/**
		 *  Step 4. Encrypt the Data
		 *  		1. Declare / Initialize the Data. Here the data is of type String
		 *  		2. Convert the Input Text to Bytes
		 *  		3. Encrypt the bytes using doFinal method 
		 */
		strDataToEncrypt = "Hello World of Encryption using DES ";
		byte[] byteDataToEncrypt = strDataToEncrypt.getBytes();
		byte[] byteCipherText = desCipher.doFinal(byteDataToEncrypt); 
		strCipherText = new BASE64Encoder().encode(byteCipherText);
		System.out.println("Cipher Text generated using DES with CBC mode and PKCS5 Padding is " +strCipherText);
		
		/**
		 *  Step 5. Decrypt the Data
		 *  		1. Initialize the Cipher for Decryption 
		 *  		2. Decrypt the cipher bytes using doFinal method 
		 */
		desCipher.init(Cipher.DECRYPT_MODE,secretKey,desCipher.getParameters());
		 //desCipher.init(Cipher.DECRYPT_MODE,secretKey);
		byte[] byteDecryptedText = desCipher.doFinal(byteCipherText);
		strDecryptedText = new String(byteDecryptedText);
		System.out.println(" Decrypted Text message is " +strDecryptedText);
		}
		
		catch (NoSuchAlgorithmException noSuchAlgo)
		{
			System.out.println(" No Such Algorithm exists " + noSuchAlgo);
		}
		
			catch (NoSuchPaddingException noSuchPad)
			{
				System.out.println(" No Such Padding exists " + noSuchPad);
			}
		
				catch (InvalidKeyException invalidKey)
				{
					System.out.println(" Invalid Key " + invalidKey);
				}
				
				catch (BadPaddingException badPadding)
				{
					System.out.println(" Bad Padding " + badPadding);
				}
				
				catch (IllegalBlockSizeException illegalBlockSize)
				{
					System.out.println(" Illegal Block Size " + illegalBlockSize);
				}
				
				catch (InvalidAlgorithmParameterException invalidParam)
				{
					System.out.println(" Invalid Parameter " + invalidParam);
				}
	}

}


Detalles de Traducción

  1. POR ABALCO DAVID Y CASTRO WILSON
  2. ESCUELA POLITÉCNICA NACIONAL
  3. APLICACIONES EN AMBIENTES LIBRES
  4. TUTOR: TITO ARMAS
  5. 15/11/2012
  6. QUITO-ECUADOR
  7. Con la colaboración de Juan Carlos Calderón (Ejemplos de código)