Package javax.crypto

Examples of javax.crypto.SecretKey


     
        // hash is 20 bytes so we've got 4 zeros at the end. tough
     
      System.arraycopy( hash, 0, key_data, 0, hash.length );
     
      SecretKey tdes_key = new SecretKeySpec( key_data, "DESede" );

      Cipher cipher = Cipher.getInstance("DESede")// Triple-DES encryption

      cipher.init(mode, tdes_key );
           
View Full Code Here


    }
    // Create the PBE secret key
    PBEParameterSpec cipherSpec = new PBEParameterSpec(this.salt, this.iterationCount);
    PBEKeySpec keySpec = new PBEKeySpec(this.pbepass);
    SecretKeyFactory factory = SecretKeyFactory.getInstance(this.pbealgo);
    SecretKey cipherKey = factory.generateSecret(keySpec);
    // Decode the secret
    byte[] encoding = Base64Utils.fromb64(secret);
    Cipher cipher = Cipher.getInstance(this.pbealgo);
    cipher.init(Cipher.DECRYPT_MODE, cipherKey, cipherSpec);
    byte[] decode = cipher.doFinal(encoding);
View Full Code Here

        Key secretKey = new SecretKeySpec(key, DEFAULT_SYM_KEY_ALGORITHM);
        return new SymmetricCryptor(secretKey);
    }
   
    public static void generateAndSaveKey(String file) throws CryptoException, IOException {
      SecretKey key = generateKey();
      saveKey(file, key);
    }
View Full Code Here

      throw new IllegalArgumentException(
      "unencrypted string was null or empty" );
   
    try
    {
      SecretKey key = keyFactory.generateSecret( keySpec );
      cipher.init( Cipher.ENCRYPT_MODE, key );
      byte[] cleartext = unencryptedString.getBytes( UNICODE_FORMAT );
      byte[] ciphertext = cipher.doFinal( cleartext );
     
      return new String( Base64.encode( ciphertext ));
View Full Code Here

    if ( encryptedString == null || encryptedString.trim().length() <= 0 )
      throw new IllegalArgumentException( "encrypted string was null or empty" );
   
    try
    {
      SecretKey key = keyFactory.generateSecret( keySpec );
      cipher.init( Cipher.DECRYPT_MODE, key );
      byte[] cleartext = Base64.decode( encryptedString );
      byte[] ciphertext = cipher.doFinal( cleartext );
     
      return bytes2String( ciphertext );
View Full Code Here

    // ��ԭʼ�ܳ����ݴ���DESKeySpec����
    DESKeySpec dks = new DESKeySpec(key);
    // ����һ���ܳ׹�����Ȼ��������DESKeySpecת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
    SecretKey securekey = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɼ��ܲ���
    Cipher cipher = Cipher.getInstance(DES);
    // ���ܳ׳�ʼ��Cipher����
    cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
    // ���ڣ���ȡ���ݲ�����
View Full Code Here

    // ��ԭʼ�ܳ����ݴ���һ��DESKeySpec����
    DESKeySpec dks = new DESKeySpec(key);
    // ����һ���ܳ׹�����Ȼ��������DESKeySpec����ת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
    SecretKey securekey = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɽ��ܲ���
    Cipher cipher = Cipher.getInstance(DES);
    // ���ܳ׳�ʼ��Cipher����
    cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
    // ���ڣ���ȡ���ݲ�����
View Full Code Here

    // ��ԭʼ�ܳ����ݴ���DESKeySpec����
    DESKeySpec dks = new DESKeySpec(key);
    // ����һ���ܳ׹�����Ȼ��������DESKeySpecת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
    SecretKey securekey = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɼ��ܲ���
    Cipher cipher = Cipher.getInstance(DES);
    // ���ܳ׳�ʼ��Cipher����
    cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
    // ���ڣ���ȡ���ݲ�����
View Full Code Here

    // ��ԭʼ�ܳ����ݴ���һ��DESKeySpec����
    DESKeySpec dks = new DESKeySpec(key);
    // ����һ���ܳ׹�����Ȼ��������DESKeySpec����ת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
    SecretKey securekey = keyFactory.generateSecret(dks);
    // Cipher����ʵ����ɽ��ܲ���
    Cipher cipher = Cipher.getInstance(DES);
    // ���ܳ׳�ʼ��Cipher����
    cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
    // ���ڣ���ȡ���ݲ�����
View Full Code Here

     
      PBEKeySpec keySpec = new PBEKeySpec(password);
   
      SecretKeyFactory keyFactory = SecretKeyFactory.getInstance( PBE_ALG );
   
      SecretKey key = keyFactory.generateSecret(keySpec);
   
      PBEParameterSpec paramSpec = new PBEParameterSpec( salt, PBE_ITERATIONS );
   
      Cipher cipher = Cipher.getInstance( PBE_ALG );
     
View Full Code Here

TOP

Related Classes of javax.crypto.SecretKey

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.