Package javax.crypto.spec

Examples of javax.crypto.spec.DESKeySpec


      {
        keySpec = new DESedeKeySpec( keyAsBytes );
      }
      else if ( encryptionScheme.equals( DES_ENCRYPTION_SCHEME ) )
      {
        keySpec = new DESKeySpec( keyAsBytes );
      }
      else
      {
        throw new IllegalArgumentException( "Encryption scheme not supported: "
            + encryptionScheme );
View Full Code Here


  public static byte[] encrypt(byte[] src, byte[] key)
    throws Exception {
    //    DES�㷨Ҫ����һ�������ε������Դ
    SecureRandom sr = new SecureRandom();
    // ��ԭʼ�ܳ����ݴ���DESKeySpec����
    DESKeySpec dks = new DESKeySpec(key);
    // ����һ���ܳ׹�����Ȼ��������DESKeySpecת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
    SecretKey securekey = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɼ��ܲ���
View Full Code Here

  public static byte[] decrypt(byte[] src, byte[] key)
    throws Exception {
    //    DES�㷨Ҫ����һ�������ε������Դ
    SecureRandom sr = new SecureRandom();
    // ��ԭʼ�ܳ����ݴ���һ��DESKeySpec����
    DESKeySpec dks = new DESKeySpec(key);
    // ����һ���ܳ׹�����Ȼ��������DESKeySpec����ת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
    SecretKey securekey = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɽ��ܲ���
View Full Code Here

  public static byte[] encrypt(byte[] src, byte[] key)
    throws Exception {
    //    DES�㷨Ҫ����һ�������ε������Դ
    SecureRandom sr = new SecureRandom();
    // ��ԭʼ�ܳ����ݴ���DESKeySpec����
    DESKeySpec dks = new DESKeySpec(key);
    // ����һ���ܳ׹�����Ȼ��������DESKeySpecת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
    SecretKey securekey = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɼ��ܲ���
View Full Code Here

  public static byte[] decrypt(byte[] src, byte[] key)
    throws Exception {
    //    DES�㷨Ҫ����һ�������ε������Դ
    SecureRandom sr = new SecureRandom();
    // ��ԭʼ�ܳ����ݴ���һ��DESKeySpec����
    DESKeySpec dks = new DESKeySpec(key);
    // ����һ���ܳ׹�����Ȼ��������DESKeySpec����ת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
    SecretKey securekey = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɽ��ܲ���
View Full Code Here

public class DESFactory {

  public DESFactory(byte encKey[], byte desKey[]) throws Exception {
    SecureRandom sr = new SecureRandom();
    byte rawKeyData[] = encKey;
    DESKeySpec dks = new DESKeySpec(rawKeyData);
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
    javax.crypto.SecretKey key = keyFactory.generateSecret(dks);
    enCipher = Cipher.getInstance("DES");
    enCipher.init(1, key, sr);
    rawKeyData = desKey;
    dks = new DESKeySpec(rawKeyData);
    key = keyFactory.generateSecret(dks);
    deCipher = Cipher.getInstance("DES");
    deCipher.init(2, key, sr);
  }
View Full Code Here

  }

  public byte[] doDecrypt(byte encryptText[]) throws Exception {
    SecureRandom sr = new SecureRandom();
    byte rawKeyData[] = desKey;
    DESKeySpec dks = new DESKeySpec(rawKeyData);
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
    javax.crypto.SecretKey key = keyFactory.generateSecret(dks);
    Cipher cipher = Cipher.getInstance("DES");
    cipher.init(2, key, sr);
    byte encryptedData[] = encryptText;
View Full Code Here

  }

  public byte[] doEncrypt(byte plainText[]) throws Exception {
    SecureRandom sr = new SecureRandom();
    byte rawKeyData[] = desKey;
    DESKeySpec dks = new DESKeySpec(rawKeyData);
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
    javax.crypto.SecretKey key = keyFactory.generateSecret(dks);
    Cipher cipher = Cipher.getInstance("DES");
    cipher.init(1, key, sr);
    byte data[] = plainText;
View Full Code Here

    this.algorithm = algorithm;
    // DES算法要求有一个可信任的随机数源
    SecureRandom sr = new SecureRandom();
    try {
      // 从原始密匙数据创建DESKeySpec对象
      DESKeySpec dks = new DESKeySpec(key);
      // 创建一个密匙工厂,然后用它把DESKeySpec转换成
      // 一个SecretKey对象
      SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(algorithm);
      SecretKey secretKey = keyFactory.generateSecret(dks);
      // Cipher对象实际完成加密操作
View Full Code Here

  /**
   * Encrypts griven string with given pass-phrase with DES.
   */
  public static String cipher(String msg, byte[] passPhrase) {
    try {
      KeySpec keySpec = new DESKeySpec(passPhrase);
      SecretKey key = SecretKeyFactory.getInstance("DES").generateSecret(
          keySpec);
      Cipher cipher = Cipher.getInstance(key.getAlgorithm());
      cipher.init(Cipher.ENCRYPT_MODE, key);
      return toHexString(cipher.doFinal(msg.getBytes()));
View Full Code Here

TOP

Related Classes of javax.crypto.spec.DESKeySpec

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.