-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NTLMCryptography: Add .NET 5.0 \ 6.0 support
- Loading branch information
Showing
2 changed files
with
36 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* Copyright (C) 2014-2019 Tal Aloni <[email protected]>. All rights reserved. | ||
/* Copyright (C) 2014-2023 Tal Aloni <[email protected]>. All rights reserved. | ||
* | ||
* You can redistribute this program and/or modify it under the terms of | ||
* the GNU Lesser Public License as published by the Free Software Foundation, | ||
|
@@ -27,6 +27,15 @@ public void LMv1HashTest() | |
Assert.IsTrue(ByteUtils.AreByteArraysEqual(hash, expected)); | ||
} | ||
|
||
// Will use weak DES key | ||
[TestMethod] | ||
public void LMv1HashTestEmptyPassword() | ||
{ | ||
byte[] hash = NTLMCryptography.LMOWFv1(""); | ||
byte[] expected = new byte[] { 0xaa, 0xd3, 0xb4, 0x35, 0xb5, 0x14, 0x04, 0xee, 0xaa, 0xd3, 0xb4, 0x35, 0xb5, 0x14, 0x04, 0xee }; | ||
Assert.IsTrue(ByteUtils.AreByteArraysEqual(hash, expected)); | ||
} | ||
|
||
[TestMethod] | ||
public void NTv1HashTest() | ||
{ | ||
|
@@ -155,6 +164,7 @@ public void NTLMv2AuthenticateMessageTest() | |
public void TestAll() | ||
{ | ||
LMv1HashTest(); | ||
LMv1HashTestEmptyPassword(); | ||
NTv1HashTest(); | ||
NTv2HashTest(); | ||
LMv1ResponseTest(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* Copyright (C) 2014-2017 Tal Aloni <[email protected]>. All rights reserved. | ||
/* Copyright (C) 2014-2023 Tal Aloni <[email protected]>. All rights reserved. | ||
* | ||
* You can redistribute this program and/or modify it under the terms of | ||
* the GNU Lesser Public License as published by the Free Software Foundation, | ||
|
@@ -78,11 +78,26 @@ public static ICryptoTransform CreateWeakDesEncryptor(CipherMode mode, byte[] rg | |
{ | ||
DES des = DES.Create(); | ||
des.Mode = mode; | ||
DESCryptoServiceProvider sm = des as DESCryptoServiceProvider; | ||
MethodInfo mi = sm.GetType().GetMethod("_NewEncryptor", BindingFlags.NonPublic | BindingFlags.Instance); | ||
object[] Par = { rgbKey, mode, rgbIV, sm.FeedbackSize, 0 }; | ||
ICryptoTransform trans = mi.Invoke(sm, Par) as ICryptoTransform; | ||
return trans; | ||
ICryptoTransform transform; | ||
if (DES.IsWeakKey(rgbKey) || DES.IsSemiWeakKey(rgbKey)) | ||
{ | ||
#if NETSTANDARD2_0 | ||
MethodInfo getTransformCoreMethodInfo = des.GetType().GetMethod("CreateTransformCore", BindingFlags.NonPublic | BindingFlags.Static); | ||
object[] getTransformCoreParameters = { mode, des.Padding, rgbKey, rgbIV, des.BlockSize / 8 , des.FeedbackSize / 8, des.BlockSize / 8, true }; | ||
transform = getTransformCoreMethodInfo.Invoke(null, getTransformCoreParameters) as ICryptoTransform; | ||
#else | ||
DESCryptoServiceProvider desServiceProvider = des as DESCryptoServiceProvider; | ||
MethodInfo newEncryptorMethodInfo = desServiceProvider.GetType().GetMethod("_NewEncryptor", BindingFlags.NonPublic | BindingFlags.Instance); | ||
object[] encryptorParameters = { rgbKey, mode, rgbIV, desServiceProvider.FeedbackSize, 0 }; | ||
transform = newEncryptorMethodInfo.Invoke(desServiceProvider, encryptorParameters) as ICryptoTransform; | ||
#endif | ||
} | ||
else | ||
{ | ||
transform = des.CreateEncryptor(rgbKey, rgbIV); | ||
} | ||
|
||
return transform; | ||
} | ||
|
||
/// <summary> | ||
|
@@ -123,7 +138,11 @@ public static byte[] DesLongEncrypt(byte[] key, byte[] plainText) | |
|
||
public static Encoding GetOEMEncoding() | ||
{ | ||
#if NETSTANDARD2_0 | ||
return ASCIIEncoding.GetEncoding(28591); | ||
#else | ||
return Encoding.GetEncoding(CultureInfo.CurrentCulture.TextInfo.OEMCodePage); | ||
#endif | ||
} | ||
|
||
/// <summary> | ||
|