public byte[] encryptData(PublicKey key,byte[] data)
    {
    	try {
    		if(data==null || data.length<=0)
    		{
    			return null;
    		}
			Cipher cipher=Cipher.getInstance(algorithm);
			cipher.init(Cipher.ENCRYPT_MODE, key);
			return cipher.doFinal(data);
		} catch (Exception e) {
			log.error(e.getMessage(),e);
		}
    	return null;
    }
public byte [ ] encryptData ( PublicKey key , byte [ ] data ) { try { if ( data == null || data . length <= 0 ) { return null ; } Cipher cipher = Cipher . getInstance ( algorithm ) ; cipher . init ( Cipher . ENCRYPT_MODE , key ) ; return cipher . doFinal ( data ) ; } catch ( Exception e ) { log . error ( e . getMessage ( ) , e ) ; } return null ; }
使用公钥加密数据
@param key
@param data 待加密数据
@return