public virtual void Init(bool forEncryption, ICipherParameters parameters) { encrypting = forEncryption; if (parameters is RC2Parameters) { RC2Parameters rC2Parameters = (RC2Parameters)parameters; workingKey = GenerateWorkingKey(rC2Parameters.GetKey(), rC2Parameters.EffectiveKeyBits); return; } if (parameters is KeyParameter) { KeyParameter keyParameter = (KeyParameter)parameters; byte[] key = keyParameter.GetKey(); workingKey = GenerateWorkingKey(key, key.Length * 8); return; } throw new ArgumentException("invalid parameter passed to RC2 init - " + Platform.GetTypeName(parameters)); }
public virtual void Init(bool forEncryption, ICipherParameters parameters) { this.encrypting = forEncryption; if (parameters is RC2Parameters) { RC2Parameters parameters2 = (RC2Parameters)parameters; this.workingKey = this.GenerateWorkingKey(parameters2.GetKey(), parameters2.EffectiveKeyBits); } else { if (!(parameters is KeyParameter)) { throw new ArgumentException("invalid parameter passed to RC2 init - " + Platform.GetTypeName(parameters)); } byte[] key = ((KeyParameter)parameters).GetKey(); this.workingKey = this.GenerateWorkingKey(key, key.Length * 8); } }
public void Init(int cipherMode, IKey key, AlgorithmParameterSpec aps) { ICipherParameters cp; if (aps is RC2ParameterSpec) { cp = new RC2Parameters(key.GetEncoded(), (aps as RC2ParameterSpec).GetEffectiveKeyBits()); } else if (aps is IvParameterSpec) { cp = new KeyParameter(key.GetEncoded()); cp = new ParametersWithIV(cp, (aps as IvParameterSpec).GetIV()); } else { throw new NotImplementedException(); } cipherImpl.Init(cipherMode == ENCRYPT_MODE, cp); }
public ITestResult Perform() { byte[] kek1 = Hex.Decode("fd04fd08060707fb0003fefffd02fe05"); byte[] iv1 = Hex.Decode("c7d90059b29e97f7"); byte[] in1 = Hex.Decode("b70a25fbc9d86a86050ce0d711ead4d9"); byte[] out1 = Hex.Decode("70e699fb5701f7833330fb71e87c85a420bdc99af05d22af5a0e48d35f3138986cbaafb4b28d4f35"); // // note the RFC 3217 test specifies a key to be used with an effective key size of // 40 bits which is why it is done here - in practice nothing less than 128 bits should be used. // ICipherParameters paramWrap = new ParametersWithRandom(new ParametersWithIV(new RC2Parameters(kek1, 40), iv1), new RFCRandom()); ICipherParameters paramUnwrap = new RC2Parameters(kek1, 40); ITestResult result = wrapTest(1, paramWrap, paramUnwrap, in1, out1); if (!result.IsSuccessful()) { return(result); } return(new SimpleTestResult(true, Name + ": Okay")); }
/** * initialise a RC2 cipher. * * @param forEncryption whether or not we are for encryption. * @param params the parameters required to set up the cipher. * @exception ArgumentException if the params argument is * inappropriate. */ public void init( bool encrypting, CipherParameters parameters) { this.encrypting = encrypting; if (typeof(RC2Parameters).IsInstanceOfType(parameters)) { RC2Parameters param = (RC2Parameters)parameters; workingKey = generateWorkingKey(param.getKey(), param.getEffectiveKeyBits()); } else if (typeof(KeyParameter).IsInstanceOfType(parameters)) { byte[] key = ((KeyParameter)parameters).getKey(); workingKey = generateWorkingKey(key, key.Length * 8); } else { throw new ArgumentException("invalid parameter passed to RC2 init - " + parameters.GetType().ToString()); } }
/** * initialise a RC2 cipher. * * @param forEncryption whether or not we are for encryption. * @param parameters the parameters required to set up the cipher. * @exception ArgumentException if the parameters argument is * inappropriate. */ public virtual void Init( bool forEncryption, ICipherParameters parameters) { this.encrypting = forEncryption; if (parameters is RC2Parameters) { RC2Parameters param = (RC2Parameters)parameters; workingKey = GenerateWorkingKey(param.GetKey(), param.EffectiveKeyBits); } else if (parameters is KeyParameter) { KeyParameter param = (KeyParameter)parameters; byte[] key = param.GetKey(); workingKey = GenerateWorkingKey(key, key.Length * 8); } else { throw new ArgumentException("invalid parameter passed to RC2 init - " + parameters.GetType().Name); } }
/** * initialise a RC2 cipher. * * @param forEncryption whether or not we are for encryption. * @param parameters the parameters required to set up the cipher. * @exception ArgumentException if the parameters argument is * inappropriate. */ public virtual void Init( bool forEncryption, ICipherParameters parameters) { this.encrypting = forEncryption; if (parameters is RC2Parameters) { RC2Parameters param = (RC2Parameters)parameters; workingKey = GenerateWorkingKey(param.GetKey(), param.EffectiveKeyBits); } else if (parameters is KeyParameter) { KeyParameter param = (KeyParameter)parameters; byte[] key = param.GetKey(); workingKey = GenerateWorkingKey(key, key.Length * 8); } else { throw new ArgumentException("invalid parameter passed to RC2 init - " + BestHTTP.SecureProtocol.Org.BouncyCastle.Utilities.Platform.GetTypeName(parameters)); } }
public void Init(int cipherMode, IKey key) { ICipherParameters cp = new RC2Parameters(key.GetEncoded()); cipherImpl.Init(cipherMode == ENCRYPT_MODE, cp); }