3초기억력

sha512 hash 데이터 생성 함수 본문

플밍_ASP

sha512 hash 데이터 생성 함수

잠수콩 2024. 5. 10. 14:31

Function Hash(ByVal Input, HashAlgorithm, CharSet, Encoding)
    
    ' Select the System.Security.Cryptography value.
    
    Select Case uCase(HashAlgorithm)
    
        Case "MD5"
        
            HashAlgorithm = "MD5CryptoServiceProvider"
            
        Case "SHA1"
        
            HashAlgorithm = "SHA1CryptoServiceProvider"
            
        Case "SHA2","SHA256"
        
            HashAlgorithm = "SHA256Managed"
            
        Case "SHA384"
        
            HashAlgorithm = "SHA384Managed"
            
        Case "SHA5","SHA512"
        
            HashAlgorithm = "SHA512Managed"
            
        Case Else
        
            HashAlgorithm = "SHA1CryptoServiceProvider"
    
    End Select
    
    ' Convert the input to bytes if not already.
                
    If NOT VarType(Input) = 8209 Then
                    
        Dim CS : Set CS = Server.CreateObject("System.Text." & CharSet & "Encoding")
        
            Input = CS.GetBytes_4(Input)
                                            
        Set CS = Nothing
        
    End If
    
    ' Perform the hash.
                
    Dim hAlg : Set hAlg = Server.CreateObject("System.Security.Cryptography." & HashAlgorithm)
    Dim hEnc : Set hEnc = Server.CreateObject("MSXML2.DomDocument").CreateElement("encode")
        
        Encoding = lCase(Encoding)
        
        If Encoding = "base64" OR Encoding = "b64" Then
        
            hEnc.dataType = "bin.base64"
        
        Else
        
            hEnc.dataType = "bin.hex"
        
        End If
        
        hEnc.nodeTypedValue = hAlg.ComputeHash_2((Input))
        Hash = hEnc.Text
        
        Hash = Replace(Hash,VBlf,"")
            
    Set hEnc = Nothing
    Set hAlg = Nothing
    
End Function

Dim password, salt, saltedPassword

password = "xxx"
salt = "yyy"

saltedPassword = salt & password

Response.Write(Hash(saltedPassword,"SHA512","Unicode","Base64"))​




출처 : https://stackoverflow.com/questions/72059249/translate-sha512-hash-function-from-classic-asp-to-php-laravel

Comments