Hi I have a very limited understanding of Python and have given this the best shot i have but still have not been able to get it working.
Is there anyone that knows how to get this into a .net assembly?
This is my attempt at this:
Is there anyone that knows how to get this into a .net assembly?
Code:
_________________________________________________________
def encrypt_password(challenge, password):
if challenge['algorithm'] == 'md5':
inner = md5(challenge['salt'] + password).hexdigest()
elif challenge['algorithm'] == 'sha1':
inner = sha(challenge['salt'] + password).hexdigest()
else:
raise NotImplementedError(
"Password encryption algorithm '%s' not implemented." %
challenge['algorithm'])
return md5(inner + challenge['nonce']).hexdigest()
_________________________________________________________
Code:
_________________________________________________________
public static String GetEncryptedPassword(String password, String username)
{
INoncesChallengeUser proxyNoncesChallengeUser = XmlRpcProxyGen.Create<INoncesChallengeUser>();
XmlRpcStruct NoncesChallengeUser = proxyNoncesChallengeUser.GetNoncesChallengeUser(username);
StringBuilder s = new StringBuilder();
String nonce = (String)NoncesChallengeUser["nonce"];
String salt = (String)NoncesChallengeUser["salt"];
String algorithm = (String)NoncesChallengeUser["algorithm"];
byte[] nonceBytes = new byte[nonce.Length];
byte[] saltBytes = new byte[salt.Length];
byte[] passwordBytes = new byte[password.Length];
byte[] algorithmBytes = new byte[salt.Length + password.Length];
byte[] InnerBytes;
saltBytes = Encoding.UTF8.GetBytes(salt);
passwordBytes = Encoding.UTF8.GetBytes(password);
nonceBytes = Encoding.UTF8.GetBytes(nonce);
//Copy password bytes into resulting array
for (int i = 0; i < passwordBytes.Length; i++)
algorithmBytes[i] = passwordBytes[i];
//Append salt bytes to the resulting array.
for (int i = 0; i < saltBytes.Length; i++)
algorithmBytes[saltBytes.Length + i] = saltBytes[i];
switch (algorithm.ToUpper())
{
case "SHA1":
//String encrypted_password = md5(sha1(salt + password) + nonce);
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
InnerBytes = sha1.ComputeHash(algorithmBytes);
break;
default: //MD5
//String encrypted_password = md5(sha1(salt + password) + nonce);
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
InnerBytes = md5.ComputeHash(algorithmBytes);
break;
}
//Create finalEncryptedPassword array
byte[] encryptedPasswordBytes = new byte[InnerBytes.Length + nonceBytes.Length];
//Copy inner bytes into resulting array
for (int i = 0; i < InnerBytes.Length; i++)
encryptedPasswordBytes[i] = InnerBytes[i];
//Append nonce bytes to the resulting array.
for (int i = 0; i < nonceBytes.Length; i++)
encryptedPasswordBytes[InnerBytes.Length + i] = nonceBytes[i];
//Now do the final md5 Encryption
byte[] finalEncryptedPasswordBytes = new byte[32];
MD5CryptoServiceProvider md5Final = new MD5CryptoServiceProvider();
finalEncryptedPasswordBytes = md5Final.ComputeHash(encryptedPasswordBytes);
foreach (byte b in finalEncryptedPasswordBytes)
{
s.Append(b.ToString("x2").ToLower());
}
return s.ToString();
}
_________________________________________________________
Comment