當前位置: 首頁>>代碼示例>>Java>>正文


Java SecretKeySpec.getEncoded方法代碼示例

本文整理匯總了Java中javax.crypto.spec.SecretKeySpec.getEncoded方法的典型用法代碼示例。如果您正苦於以下問題:Java SecretKeySpec.getEncoded方法的具體用法?Java SecretKeySpec.getEncoded怎麽用?Java SecretKeySpec.getEncoded使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.crypto.spec.SecretKeySpec的用法示例。


在下文中一共展示了SecretKeySpec.getEncoded方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCipher

import javax.crypto.spec.SecretKeySpec; //導入方法依賴的package包/類
private RC4Engine
getCipher(
	byte[]			key )
{
    SecretKeySpec	secret_key_spec = new SecretKeySpec( key, "RC4" );

    RC4Engine rc4_engine	= new RC4Engine();

	CipherParameters	params_a = new KeyParameter( secret_key_spec.getEncoded());

		// for RC4 enc/dec is irrelevant

	rc4_engine.init( true, params_a );

		// skip first 1024 bytes of stream to protected against a Fluhrer, Mantin and Shamir attack

   	byte[]	temp = new byte[1024];

   	rc4_engine.processBytes( temp, 0, temp.length, temp, 0 );

   	return( rc4_engine );
}
 
開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:23,代碼來源:UDPConnectionSet.java

示例2: TransportCipher

import javax.crypto.spec.SecretKeySpec; //導入方法依賴的package包/類
TransportCipher(
	String					algorithm,
	int						mode,
	SecretKeySpec			key_spec )

	throws Exception
{
    if ( algorithm.equals( "RC4" )){

    	if ( !internal_rc4 ){

    		try{
    	    	cipher = Cipher.getInstance( algorithm );

    	    	cipher.init( mode, key_spec );

    		}catch( Throwable e ){

    			internal_rc4	= true;
    		}
    	}

    	if ( internal_rc4 ){

    		rc4_engine	= new RC4Engine();

    		CipherParameters	params = new KeyParameter(key_spec.getEncoded());

    		rc4_engine.init( mode == Cipher.ENCRYPT_MODE, params );
    	}

    	//System.out.println( "RC4 key: " + ByteFormatter.encodeString( key_spec.getEncoded()));

   			// skip first 1024 bytes of stream to protected against a Fluhrer, Mantin and Shamir attack

    	byte[]	temp = new byte[1024];

    	temp = update( temp );

    	//System.out.println( "RC4: first discard = " + ByteFormatter.encodeString( temp, 0, 4 ));
    }else{

    	cipher = Cipher.getInstance( algorithm );

    	cipher.init( mode, key_spec );
    }
}
 
開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:48,代碼來源:TransportCipher.java


注:本文中的javax.crypto.spec.SecretKeySpec.getEncoded方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。