public Init ( bool forEncryption, ICipherParameters parameters ) : void | ||
forEncryption | bool | |
parameters | ICipherParameters | |
return | void |
public override void PerformTest() { BufferedBlockCipher cipher = new BufferedBlockCipher(engine); cipher.Init(true, param); byte[] outBytes = new byte[input.Length]; int len1 = cipher.ProcessBytes(input, 0, input.Length, outBytes, 0); cipher.DoFinal(outBytes, len1); if (!AreEqual(outBytes, output)) { Fail("failed - " + "expected " + Hex.ToHexString(output) + " got " + Hex.ToHexString(outBytes)); } cipher.Init(false, param); int len2 = cipher.ProcessBytes(output, 0, output.Length, outBytes, 0); cipher.DoFinal(outBytes, len2); if (!AreEqual(input, outBytes)) { Fail("failed reversal got " + Hex.ToHexString(outBytes)); } }
private IBufferedCipher CreateRijndael(WinzipAesEncryptionData winzipAesEncryptionData) { var blockCipher = new BufferedBlockCipher(new RijndaelEngine()); var param = new KeyParameter(winzipAesEncryptionData.KeyBytes); blockCipher.Init(true, param); return blockCipher; }
public static Stream encryptStream(Stream stream) { BufferedBlockCipher output = new BufferedBlockCipher(new CfbBlockCipher(new AesFastEngine(), 8)); output.Init(true, new ParametersWithIV(new KeyParameter(SecretKey), SecretKey, 0, 16)); BufferedBlockCipher input = new BufferedBlockCipher(new CfbBlockCipher(new AesFastEngine(), 8)); input.Init(false, new ParametersWithIV(new KeyParameter(SecretKey), SecretKey, 0, 16)); return new CipherStream(stream, input, output); }
public BouncyCastleAesStream(Stream stream, byte[] key) { _baseStream = stream; _encryptCipher = new BufferedBlockCipher(new CfbBlockCipher(new AesFastEngine(), 8)); _encryptCipher.Init(true, new ParametersWithIV(new KeyParameter(key), key, 0, 16)); _decryptCipher = new BufferedBlockCipher(new CfbBlockCipher(new AesFastEngine(), 8)); _decryptCipher.Init(false, new ParametersWithIV(new KeyParameter(key), key, 0, 16)); }
public BouncyCastleAes(ITCPClient tcp, byte[] key) { Stream = tcp.GetStream(); EncryptCipher = new BufferedBlockCipher(new CfbBlockCipher(new AesFastEngine(), 8)); EncryptCipher.Init(true, new ParametersWithIV(new KeyParameter(key), key, 0, 16)); DecryptCipher = new BufferedBlockCipher(new CfbBlockCipher(new AesFastEngine(), 8)); DecryptCipher.Init(false, new ParametersWithIV(new KeyParameter(key), key, 0, 16)); }
public AesStream(Stream stream, byte[] key) { BaseStream = stream; Key = key; encryptCipher = new BufferedBlockCipher(new CfbBlockCipher(new AesFastEngine(), 8)); encryptCipher.Init(true, new ParametersWithIV( new KeyParameter(key), key, 0, 16)); decryptCipher = new BufferedBlockCipher(new CfbBlockCipher(new AesFastEngine(), 8)); decryptCipher.Init(false, new ParametersWithIV( new KeyParameter(key), key, 0, 16)); }
public override void PerformTest() { BufferedBlockCipher cipher = new BufferedBlockCipher(engine); cipher.Init(true, param); byte[] outBytes = new byte[input.Length]; Array.Copy(input, 0, outBytes, 0, outBytes.Length); for (int i = 0; i != iterations; i++) { int len1 = cipher.ProcessBytes(outBytes, 0, outBytes.Length, outBytes, 0); cipher.DoFinal(outBytes, len1); } if (!AreEqual(outBytes, output)) { Fail("failed - " + "expected " + Hex.ToHexString(output) + " got " + Hex.ToHexString(outBytes)); } cipher.Init(false, param); for (int i = 0; i != iterations; i++) { int len1 = cipher.ProcessBytes(outBytes, 0, outBytes.Length, outBytes, 0); cipher.DoFinal(outBytes, len1); } if (!AreEqual(input, outBytes)) { Fail("failed reversal"); } }
public AesStream(Stream stream, byte[] key) { BaseStream = stream; Key = key; #if MONO encryptCipher = new BufferedBlockCipher(new CfbBlockCipher(new AesFastEngine(), 8)); encryptCipher.Init(true, new ParametersWithIV( new KeyParameter(key), key, 0, 16)); decryptCipher = new BufferedBlockCipher(new CfbBlockCipher(new AesFastEngine(), 8)); decryptCipher.Init(false, new ParametersWithIV( new KeyParameter(key), key, 0, 16)); #else var rijndael = GenerateAES(key); var encryptTransform = rijndael.CreateEncryptor(); var decryptTransform = rijndael.CreateDecryptor(); encryptStream = new CryptoStream(BaseStream, encryptTransform, CryptoStreamMode.Write); decryptStream = new CryptoStream(BaseStream, decryptTransform, CryptoStreamMode.Read); #endif }
public string GenerateActivationKey() { var engine = new BlowfishEngine(); var cipher = new CbcBlockCipher(engine); var bbc = new BufferedBlockCipher(cipher); bbc.Init(true, new ParametersWithIV(new KeyParameter(Encoding.ASCII.GetBytes(EncKey)), IV)); var n = Prng.Next(0, 999999); var s = String.Format("{0,6};YNAB4;;;;", n); // must be fixed length due to padding issue var sb = Encoding.ASCII.GetBytes(s); sb[sb.Length - 4] = 0x4; // sb[sb.Length - 3] = 0x4; // padding issue??? sb[sb.Length - 2] = 0x4; // PCKS#5 sb[sb.Length - 1] = 0x4; // var cipherText = new byte[bbc.GetOutputSize(sb.Length)]; var outputLen = bbc.ProcessBytes(sb, 0, sb.Length, cipherText, 0); bbc.DoFinal(sb, outputLen); var encryptedLic = Base32.EncodeByteArray(cipherText); return encryptedLic; }
private static byte[] decrypt28147cfb(byte[] key, byte[] input) { ICipherParameters param = new ParametersWithIV( new ParametersWithSBox( new KeyParameter(key), //key Gost28147Engine.GetSBox("E-A")), //type S-box Hex.Decode("0000000000000000")); //IV byte[] output = new byte[input.Length]; BufferedBlockCipher cipher = new BufferedBlockCipher(new CfbBlockCipher(new Gost28147Engine(), 64)); cipher.Init(false, param); int len1 = cipher.ProcessBytes(input, 0, input.Length, output, 0); try { cipher.DoFinal(output, len1); } catch (CryptoException ex) { //MessageBox.Show("Error: " + ex.Message); } return output; }
/// <summary> /// Encapsulates the specified links into an RSDF container. /// </summary> /// <param name="links">The links.</param> /// <returns> /// Base-16-encoded RSDF container. /// </returns> public static string CreateRSDF(string[] links) { var aes = new AesEngine(); var cfb = new CfbBlockCipher(aes, 8); var pad = new BufferedBlockCipher(cfb); var sb = new StringBuilder(); pad.Init(true, new ParametersWithIV(new KeyParameter(RSDFKey), RSDFIV)); foreach (var link in links) { var input = Encoding.UTF8.GetBytes(link); var output = new byte[input.Length]; for (var i = 0; i < input.Length; i++) { output[i] = pad.ProcessByte(input[i])[0]; } sb.Append(Convert.ToBase64String(output)); sb.Append(Environment.NewLine); } return BitConverter.ToString(Encoding.ASCII.GetBytes(sb.ToString())).Replace("-", string.Empty); }
public void EncryptStream(byte[] key) { this.NetStream.Flush(); encryptCipher = new BufferedBlockCipher(new CfbBlockCipher(new AesFastEngine(), 8)); encryptCipher.Init(true, new ParametersWithIV( new KeyParameter(key), key, 0, 16)); decryptCipher = new BufferedBlockCipher(new CfbBlockCipher(new AesFastEngine(), 8)); decryptCipher.Init(false, new ParametersWithIV( new KeyParameter(key), key, 0, 16)); encrypted = true; }
public Packet MessageDecrypt(Packet outer) { byte[] remoteKeyData = outer.Body.Take(21).ToArray(); byte[] ivData = outer.Body.Skip(21).Take(4).ToArray(); byte[] innerEncryptedData = outer.Body.Skip(25).Take(outer.Body.Length - 29).ToArray(); // Decode the body ECKeyPair remoteEphemeralKeys = ECKeyPair.LoadKeys (SecNamedCurves.GetByName ("secp160r1"), remoteKeyData, null); var idAgreement = ECDHAgree (remoteEphemeralKeys.PublicKey, Key.PrivateKey); var agreedHash = Helpers.SHA256Hash (Helpers.ToByteArray (idAgreement, 20)); var aesKey = Helpers.FoldOnce(agreedHash); // Pad out the IV byte[] aesIV = new byte[16]; Array.Clear (aesIV, 0, 16); Buffer.BlockCopy (ivData, 0, aesIV, 0, 4); // Decrypt it var cipher = new BufferedBlockCipher (new SicBlockCipher (new AesFastEngine ())); var parameters = new ParametersWithIV (new KeyParameter (aesKey), aesIV); cipher.Init (false, parameters); byte[] decryptedBody = new byte[innerEncryptedData.Length]; var offset = cipher.ProcessBytes (innerEncryptedData, decryptedBody, 0); cipher.DoFinal (decryptedBody, offset); Packet outPacket = Packet.DecodePacket (decryptedBody); return outPacket; }
private byte[] DecryptBytes(byte[] p_key, byte[] p_data) { BufferedBlockCipher cipher = new BufferedBlockCipher(new BlowfishEngine()); // init using the given key cipher.Init(false, new KeyParameter(p_key)); // decrypt the given data return cipher.ProcessBytes(p_data); }
private BufferedBlockCipher GenerateAES(byte[] key, bool forEncryption) { BufferedBlockCipher cipher = new BufferedBlockCipher(new CfbBlockCipher(new AesFastEngine(), 8)); cipher.Init(forEncryption, new ParametersWithIV(new KeyParameter(key), key)); return cipher; }