本文整理匯總了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 );
}
示例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 );
}
}