using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Modes;
using Org.BouncyCastle.Crypto.Engines;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Math;
namespace Common.Encryption
{
public class BlowfishCryptographer
{
private bool forEncryption;
private IBufferedCipher cipher;
public BlowfishCryptographer(bool forEncryption)
{
this.forEncryption = forEncryption;
cipher = new BufferedBlockCipher(new CfbBlockCipher(new BlowfishEngine(), 64));
cipher.Init(forEncryption, new ParametersWithIV(new KeyParameter(Encoding.ASCII.GetBytes("DR654dt34trg4UI6")), new byte[8]));
}
public void ReInit(byte[] IV,BigInteger pubkey)
{
cipher.Init(forEncryption, new ParametersWithIV(new KeyParameter(pubkey.ToByteArrayUnsigned()),IV));
}
public byte[] DoFinal()
{
return cipher.DoFinal();
}
public byte[] DoFinal(byte[] buffer)
{
return cipher.DoFinal(buffer);
}
public byte[] DoFinal(byte[] buffer, int startIndex, int len)
{
return cipher.DoFinal(buffer, startIndex, len);
}
public byte[] ProcessBytes(byte[] buffer)
{
return cipher.ProcessBytes(buffer);
}
public byte[] ProcessBytes(byte[] buffer, int startIndex, int len)
{
return cipher.ProcessBytes(buffer, startIndex, len);
}
public void Reset()
{
cipher.Reset();
}
}
}
если бы я сказал ProcessBytes(buf, 0, 17), он вернет только 16, я также попробовал DoFinal(), но он не выполняет свою работу! !
Это зависит от IBufferedCipher, следует ли мне использовать IStreamCipher или что-то еще, чтобы получить точное количество того, что нужно декодировать/кодировать? И я считаю, что CfbBlockCipher каким-то образом сломан или я что-то делаю неправильно.
Я использую BouncyCastel для создания CfbBlockCipher, поэтому вот коды.
[code]using System; using System.Collections.Generic; using System.Linq; using System.Text; using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto.Modes; using Org.BouncyCastle.Crypto.Engines; using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Math;
namespace Common.Encryption { public class BlowfishCryptographer { private bool forEncryption; private IBufferedCipher cipher;
public BlowfishCryptographer(bool forEncryption) { this.forEncryption = forEncryption; cipher = new BufferedBlockCipher(new CfbBlockCipher(new BlowfishEngine(), 64)); cipher.Init(forEncryption, new ParametersWithIV(new KeyParameter(Encoding.ASCII.GetBytes("DR654dt34trg4UI6")), new byte[8])); } public void ReInit(byte[] IV,BigInteger pubkey) { cipher.Init(forEncryption, new ParametersWithIV(new KeyParameter(pubkey.ToByteArrayUnsigned()),IV)); } public byte[] DoFinal() { return cipher.DoFinal(); } public byte[] DoFinal(byte[] buffer) { return cipher.DoFinal(buffer); } public byte[] DoFinal(byte[] buffer, int startIndex, int len) { return cipher.DoFinal(buffer, startIndex, len); } public byte[] ProcessBytes(byte[] buffer) { return cipher.ProcessBytes(buffer); } public byte[] ProcessBytes(byte[] buffer, int startIndex, int len) { return cipher.ProcessBytes(buffer, startIndex, len); } public void Reset() { cipher.Reset(); } } } [/code]
если бы я сказал ProcessBytes(buf, 0, 17), он вернет только 16, я также попробовал DoFinal(), но он не выполняет свою работу! ! Это зависит от IBufferedCipher, следует ли мне использовать IStreamCipher или что-то еще, чтобы получить точное количество того, что нужно декодировать/кодировать? И я считаю, что CfbBlockCipher каким-то образом сломан или я что-то делаю неправильно.