Code example for DESKeySpec

0
	 * @param keyBytes 符合DES要求的密钥 
	 * @param mode Cipher.ENCRYPT_MODE 或 Cipher.DECRYPT_MODE 
	 */ 
	private static byte[] des(byte[] inputBytes, byte[] keyBytes, int mode) {
		try { 
			DESKeySpec desKeySpec = new DESKeySpec(keyBytes);
			SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
			SecretKey secretKey = keyFactory.generateSecret(desKeySpec);
 
			Cipher cipher = Cipher.getInstance(DES);
			cipher.init(mode, secretKey);
			return cipher.doFinal(inputBytes);
		} catch (GeneralSecurityException e) {
			throw convertRuntimeException(e);
		} 
	} 
 
	/** 
	 * 生成符合DES要求的密钥, 长度为64位(8字节). 
	 */ 
	public static byte[] generateDesKey() {