You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use System.Security.Cryptography for TripleDesCipher (#1546)
* Use System.Security.Cryptography in DesCipher and TripleDesCipher; Fall back to use BouncyCastle if BCL doesn't support
* Drop DesCipher; Replace PKCS7Padding with BouncyCastle's implementation.
* Restore `CbcCipherMode`
* Restore AesCipherMode; Use BlockImpl instead of BouncyCastleImpl for 3DES-CFB on lower targets.
* Restore the xml doc comment
Copy file name to clipboardExpand all lines: src/Renci.SshNet/Security/Cryptography/Ciphers/AesCipher.BclImpl.cs
+12-17Lines changed: 12 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -52,6 +52,8 @@ public override byte[] Encrypt(byte[] input, int offset, int length)
52
52
{
53
53
if(_aes.ModeisSystem.Security.Cryptography.CipherMode.CFB or System.Security.Cryptography.CipherMode.OFB)
54
54
{
55
+
// Manually pad the input for cfb and ofb cipher mode as BCL doesn't support partial block.
56
+
// See https://github.com/dotnet/runtime/blob/e7d837da5b1aacd9325a8b8f2214cfaf4d3f0ff6/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/SymmetricPadding.cs#L20-L21
55
57
paddingLength=BlockSize-(length%BlockSize);
56
58
input=input.Take(offset,length);
57
59
length+=paddingLength;
@@ -69,6 +71,7 @@ public override byte[] Encrypt(byte[] input, int offset, int length)
@@ -89,11 +92,12 @@ public override byte[] Decrypt(byte[] input, int offset, int length)
89
92
{
90
93
if(_aes.ModeisSystem.Security.Cryptography.CipherMode.CFB or System.Security.Cryptography.CipherMode.OFB)
91
94
{
95
+
// Manually pad the input for cfb and ofb cipher mode as BCL doesn't support partial block.
96
+
// See https://github.com/dotnet/runtime/blob/e7d837da5b1aacd9325a8b8f2214cfaf4d3f0ff6/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/SymmetricPadding.cs#L20-L21
92
97
paddingLength=BlockSize-(length%BlockSize);
93
-
varnewInput=newbyte[input.Length+paddingLength];
94
-
Buffer.BlockCopy(input,offset,newInput,0,length);
95
-
input=newInput;
96
-
length=input.Length;
98
+
input=input.Take(offset,length);
99
+
length+=paddingLength;
100
+
Array.Resize(refinput,length);
97
101
offset=0;
98
102
}
99
103
}
@@ -107,6 +111,7 @@ public override byte[] Decrypt(byte[] input, int offset, int length)
0 commit comments