本文整理汇总了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 );
}
}