MySQL 설명서에 따르면 알고리즘은 이중 SHA1 해시입니다. MySQL 소스 코드를 검토 할 때 libmysql/password.c에 make_scrambled_password()라는 함수가 있습니다. 함수는 다음과 같이 정의됩니다.
/*
MySQL 4.1.1 password hashing: SHA conversion (see RFC 2289, 3174) twice
applied to the password string, and then produced octet sequence is
converted to hex string.
The result of this function is used as return value from PASSWORD() and
is stored in the database.
SYNOPSIS
make_scrambled_password()
buf OUT buffer of size 2*SHA1_HASH_SIZE + 2 to store hex string
password IN NULL-terminated password string
*/
void
make_scrambled_password(char *to, const char *password)
{
SHA1_CONTEXT sha1_context;
uint8 hash_stage2[SHA1_HASH_SIZE];
mysql_sha1_reset(&sha1_context);
/* stage 1: hash password */
mysql_sha1_input(&sha1_context, (uint8 *) password, (uint) strlen(password));
mysql_sha1_result(&sha1_context, (uint8 *) to);
/* stage 2: hash stage1 output */
mysql_sha1_reset(&sha1_context);
mysql_sha1_input(&sha1_context, (uint8 *) to, SHA1_HASH_SIZE);
/* separate buffer is used to pass 'to' in octet2hex */
mysql_sha1_result(&sha1_context, hash_stage2);
/* convert hash_stage2 to hex string */
*to++= PVERSION41_CHAR;
octet2hex(to, (const char*) hash_stage2, SHA1_HASH_SIZE);
}
이 방법을 사용하면 기본적으로 동일한 작업을 수행하는 .NET 대응 개체를 만들 수 있습니다. 여기에 내가 생각해내는 것이있다. SELECT PASSWORD ('test')를 실행할 때; MySQL을 내 로컬 복사본에 대해, 반환되는 값은 다음과 같습니다 소스 코드 (다시 password.c의)에 따르면
*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
, 처음 별표 (*)이이를 암호화 후 MySQL의 4.1 방법을 나타냅니다 암호. VB에서 기능을 에뮬레이트 할 때.
Public Function GenerateMySQLHash(ByVal strKey As String) As String
Dim keyArray As Byte() = Encoding.UTF8.GetBytes(strKey)
Dim enc = New SHA1Managed()
Dim encodedKey = enc.ComputeHash(enc.ComputeHash(keyArray))
Dim myBuilder As New StringBuilder(encodedKey.Length)
For Each b As Byte In encodedKey
myBuilder.Append(b.ToString("X2"))
Next
Return "*" & myBuilder.ToString()
End Function
가에서는 System.Security.Cryptography 네임 스페이스에) (SHA1Managed 유의 사항 : 인터넷은 예를 들어, 내가 가지고 올 것입니다. 이 메소드는 MySQL에서 PASSWORD() 호출과 동일한 출력을 리턴합니다. 이게 당신 한테 도움이되기를 바랍니다.
편집 : 여기 VB의 그물 C 번호
public string GenerateMySQLHash(string key)
{
byte[] keyArray = Encoding.UTF8.GetBytes(key);
SHA1Managed enc = new SHA1Managed();
byte[] encodedKey = enc.ComputeHash(enc.ComputeHash(keyArray));
StringBuilder myBuilder = new StringBuilder(encodedKey.Length);
foreach (byte b in encodedKey)
myBuilder.Append(b.ToString("X2"));
return "*" + myBuilder.ToString();
}
어떤 MySQL 버전을 사용하고 있습니까? 어떤 버전을 사용하고 있는지 알고 있다면 이것이 가능해야합니다. MySQL은 이중 SHA1 해시 알고리즘을 사용하여 암호를 인코딩합니다. –
mysql DB에 액세스 할 때이를 확인합니다. 게시 된 솔루션에 감사드립니다! –