Renci.SshNet.Security.Cryptography.Ciphers.RsaCipher.Encrypt C# (CSharp) Method

Encrypt() public method

Encrypts the specified data.
public Encrypt ( byte data, int offset, int length ) : byte[]
data byte The data.
offset int The zero-based offset in at which to begin encrypting.
length int The number of bytes to encrypt from .
return byte[]
        public override byte[] Encrypt(byte[] data, int offset, int length)
        {
            //  Calculate signature
            var bitLength = _key.Modulus.BitLength;

            var paddedBlock = new byte[bitLength / 8 + (bitLength % 8 > 0 ? 1 : 0) - 1];

            paddedBlock[0] = 0x01;
            for (var i = 1; i < paddedBlock.Length - length - 1; i++)
            {
                paddedBlock[i] = 0xFF;
            }

            Buffer.BlockCopy(data, offset, paddedBlock, paddedBlock.Length - length, length);

            return Transform(paddedBlock);
        }

Usage Example

Esempio n. 1
0
 public void EncryptTest()
 {
     RsaKey key = null; // TODO: Initialize to an appropriate value
     RsaCipher target = new RsaCipher(key); // TODO: Initialize to an appropriate value
     byte[] data = null; // TODO: Initialize to an appropriate value
     byte[] expected = null; // TODO: Initialize to an appropriate value
     byte[] actual;
     actual = target.Encrypt(data);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }