private byte[] BuildKey(RsaKey key) { byte[] buffer1 = key.FirstPart.ToByteArray(); byte[] buffer2 = key.SecondPart.ToByteArray(); int sizePart = 0; if ((Math.Log(buffer2.Length, 2) % 1) == 0) { sizePart = buffer2.Length; } else { sizePart = buffer2.Length + 1; } var beginList = new List <byte>(buffer1); for (int i = 0; i < sizePart - buffer1.Length; i++) { beginList.Add(0); } var endList = new List <byte>(buffer2); for (int i = 0; i < sizePart - buffer2.Length; i++) { endList.Add(0); } var result = beginList.Concat(endList); return(result.ToArray()); }
public override void Decrypt(string inputPath, string outputPath) { var file = ReadFile(inputPath); RsaKey decryptKey = RsaKeyManager.GetRsaKey(rsaKeyPath); BigInteger _d = decryptKey.FirstPart; BigInteger _n = decryptKey.SecondPart; int sizePart = GetPartKeyLength(_n); IncreaseByteArray(ref file, sizePart); RunDecrypt(outputPath, file.Length, sizePart, ref file, _d, _n); }
public override void Encrypt(string inputPath, string outputPath) { byte[] file = ReadFile(inputPath); RsaKey encryptKey = RsaKeyManager.GetRsaKey(rsaKeyPath); BigInteger _e = encryptKey.FirstPart; BigInteger _n = encryptKey.SecondPart; int sizePart = GetPartKeyLength(_n); IncreaseByteArray(ref file, sizePart - 1); RunEncrypt(outputPath, file.Length, sizePart, ref file, _e, _n); }
private void WriteKey(string filePath, KeyType type) { RsaKey key; using (var fStream = new FileStream(filePath, FileMode.Create)) { BigInteger firstNumber = 0; if ((int)type == 0) { key = new RsaKey(NumberE, NumberN); } else { key = new RsaKey(NumberD, NumberN); } var fileKay = BuildKey(key); fStream.Write(fileKay, 0, fileKay.Length); } }