2 回答
TA贡献1906条经验 获得超3个赞
在非对称密码学中,使用私钥进行加密充当签名:每个人都可以验证您是否已使用您的公钥进行签名,但只有您可以使用您的私钥进行签名(请参阅https://en.wikipedia.org/wiki/Public -key_cryptography#Digital_signatures)。显然,您必须保留一对专用于此目的的密钥。
使用 BouncyCastle 库,您可以使用 RsaEngine 实现此结果:
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Engines;
public void Test()
{
RsaEngine engine;
AsymmetricKeyParameter key;
bool forEncryption;
int chunkPosition = 0;
int i = 0;
int blockSize;
int chunkSize;
List<byte> output = new List<byte>();
byte[] byteMessageArray;
// Initialize key variable with your public or private key
// Initialize byteMessageArray with your message to be encrypted or decrypted
// Set forEncryption variable value
engine = new RsaEngine();
engine.Init(forEncryption, key);
blockSize = engine.GetInputBlockSize();
while ((chunkPosition < byteMessageArray.Length))
{
chunkSize = Math.Min(blockSize, byteMessageArray.Length - (i * blockSize));
output.AddRange(engine.ProcessBlock(byteMessageArray, chunkPosition, chunkSize));
chunkPosition = (chunkPosition + blockSize);
i += 1;
}
//Now in output you have messagge encrypted or decrypted with your private or public key
}
- 2 回答
- 0 关注
- 219 浏览
添加回答
举报