在asp中通过vbs类实现rsa加密与解密的代码

2019-01-13 22:20:49王旭

                Do 
                    q = Rnd * 1000  1 
                Loop While Not IsPrime(q) 

                 
                ' n = product of 2 primes 
                Modulus = p * q  1 

                ' random decryptor (2 to n) 
                PrivateKey = Rnd * (Modulus - 2)  1 + 2 

                lLngPhi = (p - 1) * (q - 1)  1 
                PublicKey = Euler(lLngPhi, PrivateKey) 

            Loop While PublicKey = 0 Or PublicKey = 1 

        ' Loop if we can't crypt/decrypt a byte     
        Loop While Not TestCrypt(255) 

    End Sub 

    Private Function TestCrypt(ByRef pBytData) 
        Dim lStrCrypted 
        lStrCrypted = Crypt(pBytData, PublicKey) 
        TestCrypt = Crypt(lStrCrypted, PrivateKey) = pBytData 
    End Function 

    Private Function Euler(ByRef pLngPHI, ByRef pLngKey) 

        Dim lLngR(3) 
        Dim lLngP(3) 
        Dim lLngQ(3) 

        Dim lLngCounter 
        Dim lLngResult 

        Euler = 0