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

2019-04-02 10:06:58刘景俊


' .Modulus 
'        Used with both public and private keys when encrypting 
'        and decrypting data. 

' .GenKey() 
'        Creates Public/Private key set and Modulus 

' .Crypt(pLngMessage, pLngKey)   
'        Encrypts/Decrypts message and returns  
'        as a string. 

' .Encode(pStrMessage) 
'        Encrypts message and returns in double-hex format 

' .Decode(pStrMessage) 
'        Decrypts message from double-hex format and returns a string 

Class clsRSA 

    Public PrivateKey 
    Public PublicKey 
    Public Modulus 

    Public Sub GenKey() 
        Dim lLngPhi 
        Dim q 
        Dim p 

        Randomize 

        Do 
            Do 

                ' 2 random primary numbers (0 to 1000) 
                Do 
                    p = Rnd * 1000  1 
                Loop While Not IsPrime(p) 

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

                 
                ' n = product of 2 primes