Java 8 DESedeKeySpec - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 DESedeKeySpec class.

This code example shows how to use the following methods:
 
    private String cipherAlgorithm = DEFAULT_ENCRYPTION_ALGORITHM;
 
    public final void setSecretKey(final String key) throws NoSuchAlgorithmException, InvalidKeyException,
            InvalidKeySpecException { 
        this.key = SecretKeyFactory.getInstance(this.cipherAlgorithm).generateSecret(new DESedeKeySpec(key.getBytes()));
    } 
 
    public final void setSecretKey(final Key key) {
        this.key = key;
    } 
 
    /** 
     * Note: you MUST call this method before calling setSecretKey if you're not using the default algorithm.  You've been warned. 
     * 
     * @param cipherAlgorithm the cipher algorithm. 
     */ 
    public final void setCipherAlgorithm(final String cipherAlgorithm) {
        this.cipherAlgorithm = cipherAlgorithm;
    } 
6
CodeRank
This code example shows how to use the following methods:
 
                        return new DESedeKeySpec(longKey);
                    } 
                    else 
                    { 
                        return new DESedeKeySpec(bytes);
                    } 
                } 
                catch (Exception e)
                { 
                    throw new InvalidKeySpecException(e.toString());
                } 
            } 
 
            throw new InvalidKeySpecException("Invalid KeySpec");
        } 
 
        protected SecretKey engineGenerateSecret(
            KeySpec keySpec)
        throws InvalidKeySpecException 
3
CodeRank
This code example shows how to use the following methods:
//					+ " " 
//					+ DateFormat.getTimeInstance(DateFormat.LONG).format( 
//							current); 
			 
			try { 
				this.DESspec = new DESedeKeySpec(shared_secret_key_bytes);
			} catch (InvalidKeyException ike) {
				logger.info(ike.getMessage(), ike);
			} 
			this.secret_key_spec = new SecretKeySpec(shared_secret_key_bytes,
					"DESede"); 
			//  
			IvParameterSpec DESspec = null;
			IvParameterSpec enspec = null;
			try { 
				try { 
					// Generate parameter spec to initialize my encoding, send 
					// the bytes for that parameter spec 
					// to other side 
					byte[] enspecbytes = new byte[8];
3
CodeRank
This code example shows how to use the following methods:
 
        // load the raw key 
        if (rawKey.length > 0) {
            DESedeKeySpec desedeSpec1 = null;
            try { 
                desedeSpec1 = new DESedeKeySpec(rawKey);
            } catch (InvalidKeyException e) {
                Debug.logError(e, "Not a valid DESede key", module);
                return null; 
            } 
 
            // create the SecretKey Object 
            SecretKey key = null;
            try { 
                key = skf.generateSecret(desedeSpec1);
            } catch (InvalidKeySpecException e) {
                Debug.logError(e, module);
            } 
            return key;
        } else { 
2
CodeRank
This code example shows how to use the following methods:
This code example shows how to use the following methods:
 
		private SecretKey buildSecretKey(String key) throws Exception {
			SecretKey secretKey = secretKeyCache.get(key);
			if (secretKey == null) {
				// 为上一密钥创建一个指定的 DESSede key 
				DESedeKeySpec spec = new DESedeKeySpec(key.getBytes());
				// 生成一个 DESede 密钥对象 
				secretKey = keyFactory.generateSecret(spec);
				secretKeyCache.put(key, secretKey);
			} 
			return secretKey;
		} 
 
		private String base64Encode(byte[] bytes) {
			BASE64Encoder b64e = new BASE64Encoder();
			String rs = b64e.encodeBuffer(bytes);
			if (rs != null)
				return rs.replaceAll("\\n|\\r", "");
			return rs;
		} 
3
CodeRank
This code example shows how to use the following methods:
	 */ 
	public static byte[] encryptTripleDES(String to_encrypt, String strkey)
	{ 
		try 
		{ 
			DESedeKeySpec desKeySpec = new DESedeKeySpec(strkey.getBytes());
			SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
			Key key = keyFactory.generateSecret(desKeySpec);
			Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
			cipher.init(Cipher.ENCRYPT_MODE, key);
			return cipher.doFinal(to_encrypt.getBytes());
		} 
		catch (Exception e)
		{ 
			return null; 
		} 
	} 
 
	/** 
	 * TripleDES로 암호화된 문자열을 복호화 
4
CodeRank
This code example shows how to use the following methods:
        } catch (NullPointerException e) {
            fail("Unexpected NullPointerException was thrown.");
        } catch (InvalidKeyException e) {
        } 
        try { 
            new DESedeKeySpec(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 0,
                                          1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 
                                          1, 2, 3, 4}); 
        } catch (NullPointerException e) {
            fail("Unexpected NullPointerException was thrown.");
        } catch (InvalidKeyException e) {
            fail("Unexpected InvalidKeyException was thrown.");
        } 
        try { 
            new DESedeKeySpec((byte []) null, 1);
            fail("Should raise an NullPointerException "
                    + "in case of null byte array."); 
        } catch (NullPointerException e) {
        } catch (InvalidKeyException e) {
            fail("Should raise an NullPointerException "
4
CodeRank
This code example shows how to use the following methods:
     * @throws Exception  
     */   
    public static byte[] desEncodeECB(byte[] key, byte[] data)  
            throws Exception {   
        Key deskey = null;  
        DESedeKeySpec spec = new DESedeKeySpec(key);  
        SecretKeyFactory keyfactory = SecretKeyFactory.getInstance("desede");  
        deskey = keyfactory.generateSecret(spec);  
        Cipher cipher = Cipher.getInstance("desede" + "/ECB/NoPadding");  
        cipher.init(Cipher.ENCRYPT_MODE, deskey);  
        byte[] bOut = cipher.doFinal(data);  
        return bOut;  
    }   
    /**  
     * ECB解密,不要IV  
     * @param key 密钥  
     * @param data Base64编码的密文  
     * @return 明文  
     * @throws Exception  
     */   
4
CodeRank
This code example shows how to use the following methods:

Related Java 8 DESedeKeySpec Questions & Answers:

See Code Examples for Java 8 DESedeKeySpec Methods: