@@ -28,22 +28,22 @@ public SSHCOM(byte[] data, string? passPhrase)
28
28
29
29
public Key Parse ( )
30
30
{
31
- var reader = new SshDataStream ( _data ) ;
32
- var magicNumber = reader . ReadUInt32 ( ) ;
31
+ using var dataReader = new SshDataStream ( _data ) ;
32
+ var magicNumber = dataReader . ReadUInt32 ( ) ;
33
33
if ( magicNumber != 0x3f6ff9eb )
34
34
{
35
35
throw new SshException ( "Invalid SSH2 private key." ) ;
36
36
}
37
37
38
- _ = reader . ReadUInt32 ( ) ; // Read total bytes length including magic number
39
- var keyType = reader . ReadString ( SshData . Ascii ) ;
40
- var ssh2CipherName = reader . ReadString ( SshData . Ascii ) ;
41
- var blobSize = ( int ) reader . ReadUInt32 ( ) ;
38
+ _ = dataReader . ReadUInt32 ( ) ; // Read total bytes length including magic number
39
+ var keyType = dataReader . ReadString ( SshData . Ascii ) ;
40
+ var ssh2CipherName = dataReader . ReadString ( SshData . Ascii ) ;
41
+ var blobSize = ( int ) dataReader . ReadUInt32 ( ) ;
42
42
43
43
byte [ ] keyData ;
44
44
if ( ssh2CipherName == "none" )
45
45
{
46
- keyData = reader . ReadBytes ( blobSize ) ;
46
+ keyData = dataReader . ReadBytes ( blobSize ) ;
47
47
}
48
48
else if ( ssh2CipherName == "3des-cbc" )
49
49
{
@@ -53,17 +53,17 @@ public Key Parse()
53
53
}
54
54
55
55
var key = GetCipherKey ( _passPhrase , 192 / 8 ) ;
56
- var ssh2Сipher = new TripleDesCipher ( key , new byte [ 8 ] , CipherMode . CBC , pkcs7Padding : false ) ;
57
- keyData = ssh2Сipher . Decrypt ( reader . ReadBytes ( blobSize ) ) ;
56
+ using var ssh2Сipher = new TripleDesCipher ( key , new byte [ 8 ] , CipherMode . CBC , pkcs7Padding : false ) ;
57
+ keyData = ssh2Сipher . Decrypt ( dataReader . ReadBytes ( blobSize ) ) ;
58
58
}
59
59
else
60
60
{
61
61
throw new SshException ( string . Format ( "Cipher method '{0}' is not supported." , ssh2CipherName ) ) ;
62
62
}
63
63
64
- reader = new SshDataStream ( keyData ) ;
64
+ using var keyReader = new SshDataStream ( keyData ) ;
65
65
66
- var decryptedLength = reader . ReadUInt32 ( ) ;
66
+ var decryptedLength = keyReader . ReadUInt32 ( ) ;
67
67
68
68
if ( decryptedLength > blobSize - 4 )
69
69
{
@@ -72,12 +72,12 @@ public Key Parse()
72
72
73
73
if ( keyType . Contains ( "rsa" ) )
74
74
{
75
- var exponent = ReadBigIntWithBits ( reader ) ;
76
- var d = ReadBigIntWithBits ( reader ) ;
77
- var modulus = ReadBigIntWithBits ( reader ) ;
78
- var inverseQ = ReadBigIntWithBits ( reader ) ;
79
- var q = ReadBigIntWithBits ( reader ) ;
80
- var p = ReadBigIntWithBits ( reader ) ;
75
+ var exponent = ReadBigIntWithBits ( keyReader ) ;
76
+ var d = ReadBigIntWithBits ( keyReader ) ;
77
+ var modulus = ReadBigIntWithBits ( keyReader ) ;
78
+ var inverseQ = ReadBigIntWithBits ( keyReader ) ;
79
+ var q = ReadBigIntWithBits ( keyReader ) ;
80
+ var p = ReadBigIntWithBits ( keyReader ) ;
81
81
return new RsaKey ( modulus , exponent , d , p , q , inverseQ ) ;
82
82
}
83
83
0 commit comments