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
Copy file name to clipboardExpand all lines: src/Renci.SshNet/Security/Cryptography/Ciphers/AesCipher.BclImpl.cs
+9-4Lines changed: 9 additions & 4 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)
Copy file name to clipboardExpand all lines: src/Renci.SshNet/Security/Cryptography/Ciphers/TripleDesCipher.BclImpl.cs
+19-4Lines changed: 19 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -43,6 +43,8 @@ public override byte[] Encrypt(byte[] input, int offset, int length)
43
43
{
44
44
if(_des.ModeisSystem.Security.Cryptography.CipherMode.CFB or System.Security.Cryptography.CipherMode.OFB)
45
45
{
46
+
// Manually pad the input for cfb and ofb cipher mode as BCL doesn't support partial block.
47
+
// See https://github.com/dotnet/runtime/blob/e7d837da5b1aacd9325a8b8f2214cfaf4d3f0ff6/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/SymmetricPadding.cs#L20-L21
46
48
paddingLength=BlockSize-(length%BlockSize);
47
49
input=input.Take(offset,length);
48
50
length+=paddingLength;
@@ -51,11 +53,16 @@ public override byte[] Encrypt(byte[] input, int offset, int length)
51
53
}
52
54
}
53
55
56
+
// Otherwise, (the most important case) assume this instance is
57
+
// used for one direction of an SSH connection, whereby the
58
+
// encrypted data in all packets are considered a single data
59
+
// stream i.e. we do not want to reset the state between calls to Encrypt.
@@ -74,20 +83,26 @@ public override byte[] Decrypt(byte[] input, int offset, int length)
74
83
{
75
84
if(_des.ModeisSystem.Security.Cryptography.CipherMode.CFB or System.Security.Cryptography.CipherMode.OFB)
76
85
{
86
+
// Manually pad the input for cfb and ofb cipher mode as BCL doesn't support partial block.
87
+
// See https://github.com/dotnet/runtime/blob/e7d837da5b1aacd9325a8b8f2214cfaf4d3f0ff6/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/SymmetricPadding.cs#L20-L21
77
88
paddingLength=BlockSize-(length%BlockSize);
78
-
varnewInput=newbyte[input.Length+paddingLength];
79
-
Buffer.BlockCopy(input,offset,newInput,0,length);
80
-
input=newInput;
81
-
length=input.Length;
89
+
input=input.Take(offset,length);
90
+
length+=paddingLength;
91
+
Array.Resize(refinput,length);
82
92
offset=0;
83
93
}
84
94
}
85
95
96
+
// Otherwise, (the most important case) assume this instance is
97
+
// used for one direction of an SSH connection, whereby the
98
+
// encrypted data in all packets are considered a single data
99
+
// stream i.e. we do not want to reset the state between calls to Encrypt.
Copy file name to clipboardExpand all lines: src/Renci.SshNet/Security/Cryptography/Ciphers/TripleDesCipher.cs
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -33,8 +33,9 @@ public TripleDesCipher(byte[] key, byte[] iv, BlockCipherMode mode, bool pkcs7Pa
33
33
#if !NET6_0_OR_GREATER
34
34
if(mode==BlockCipherMode.CFB)
35
35
{
36
-
// CFB8 not supported on .NET Framework
36
+
// CFB8 not supported on .NET Framework, but supported on .NET
37
37
// see https://github.com/microsoft/referencesource/blob/51cf7850defa8a17d815b4700b67116e3fa283c2/mscorlib/system/security/cryptography/tripledescryptoserviceprovider.cs#L76-L78
38
+
// see https://github.com/dotnet/runtime/blob/e7d837da5b1aacd9325a8b8f2214cfaf4d3f0ff6/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/TripleDesImplementation.cs#L229-L236
0 commit comments