digest = md.digest();
}
}
if( encRevision == 2 && length != 5 )
{
throw new CryptographyException(
"Error: Expected length=5 actual=" + length );
}
//3.3 STEP 4
byte[] rc4Key = new byte[ (int)length ];
System.arraycopy( digest, 0, rc4Key, 0, (int)length );
//3.7 step 2
if( encRevision == 2 )
{
rc4.setKey( rc4Key );
rc4.write( o, result );
}
else if( encRevision == 3 || encRevision == 4)
{
/**
byte[] iterationKey = new byte[ rc4Key.length ];
byte[] dataToEncrypt = o;
for( int i=19; i>=0; i-- )
{
System.arraycopy( rc4Key, 0, iterationKey, 0, rc4Key.length );
for( int j=0; j< iterationKey.length; j++ )
{
iterationKey[j] = (byte)(iterationKey[j] ^ (byte)i);
}
rc4.setKey( iterationKey );
rc4.write( dataToEncrypt, result );
dataToEncrypt = result.toByteArray();
result.reset();
}
result.write( dataToEncrypt, 0, dataToEncrypt.length );
*/
byte[] iterationKey = new byte[ rc4Key.length ];
byte[] otemp = new byte[ o.length ]; //sm
System.arraycopy( o, 0, otemp, 0, o.length ); //sm
rc4.write( o, result);//sm
for( int i=19; i>=0; i-- )
{
System.arraycopy( rc4Key, 0, iterationKey, 0, rc4Key.length );
for( int j=0; j< iterationKey.length; j++ )
{
iterationKey[j] = (byte)(iterationKey[j] ^ (byte)i);
}
rc4.setKey( iterationKey );
result.reset(); //sm
rc4.write( otemp, result ); //sm
otemp = result.toByteArray(); //sm
}
}
return result.toByteArray();
}
catch( NoSuchAlgorithmException e )
{
throw new CryptographyException( e );
}
}