private static String encrypt(String source) throws Exception {
        generateKeyPair();
        Key publicKey;
        ObjectInputStream ois = null;
        try {
            /** 将文件中的公钥对象读出 */
            ois = new ObjectInputStream(new FileInputStream(
                    PUBLIC_KEY_FILE));
            publicKey = (Key) ois.readObject();
        } catch (Exception e) {
            throw e;
        } finally {
            ois.close();
        }

        /** 得到Cipher对象来实现对源数据的RSA加密 */
        Cipher cipher = Cipher.getInstance(ALGORITHM);
        cipher.init(Cipher.ENCRYPT_MODE, publicKey);
        byte[] b = source.getBytes();
        /** 执行加密操作 */
        byte[] b1 = cipher.doFinal(b);
        BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(b1);
    }
private static String encrypt(String source) throws Exception {
        generateKeyPair();
        Key publicKey;
        ObjectInputStream ois = null;
        try {
            
            ois = new ObjectInputStream(new FileInputStream(
                    PUBLIC_KEY_FILE));
            publicKey = (Key) ois.readObject();
        } catch (Exception e) {
            throw e;
        } finally {
            ois.close();
        }

        
        Cipher cipher = Cipher.getInstance(ALGORITHM);
        cipher.init(Cipher.ENCRYPT_MODE, publicKey);
        byte[] b = source.getBytes();
        
        byte[] b1 = cipher.doFinal(b);
        BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(b1);
    }
private static String encrypt ( String source ) throws Exception { generateKeyPair ( ) ; Key publicKey ; ObjectInputStream ois = null ; try { /** 将文件中的公钥对象读出 */ ois = new ObjectInputStream ( new FileInputStream ( PUBLIC_KEY_FILE ) ) ; publicKey = ( Key ) ois . readObject ( ) ; } catch ( Exception e ) { throw e ; } finally { ois . close ( ) ; } /** 得到Cipher对象来实现对源数据的RSA加密 */ Cipher cipher = Cipher . getInstance ( ALGORITHM ) ; cipher . init ( Cipher . ENCRYPT_MODE , publicKey ) ; byte [ ] b = source . getBytes ( ) ; /** 执行加密操作 */ byte [ ] b1 = cipher . doFinal ( b ) ; BASE64Encoder encoder = new BASE64Encoder ( ) ; return encoder . encode ( b1 ) ; }
加密方法

@param source 源数据
@return
@throws Exception
@deprecated
加密方法