pontoNETpt
A comunidade PontoNetPT está direccionada a todos os programadores que trabalhem com a plataforma .NET.
Criptografia com RSA e Base64
Um exemplo simples de criptografia.
Atente-se apenas ao padrão das chaves que serão usadas. Mais infos em:
http://msdn.microsoft.com/pt-br/library/system.security.cryptography.xml.rsakeyvalue.rsakeyvalue.aspx

using 
System.Security.Cryptography
;

public class 
CryptographyRSA()
{
    
private string PrivateKey "<RSAKeyValue>YOUR_RSA_KEY</RSAKeyValue>"
;
    private string 
PublicKey "<RSAKeyValue>YOUR_RSA_KEY</RSAKeyValue>"
;

    public 
CryptographyRSA(){}

    
public string EncryptText(string 
strToEncript)
    {
        
byte[] bytes = new UnicodeEncoding().GetBytes(strToEncript))
;

        
RSACryptoServiceProvider provider = new RSACryptoServiceProvider()
;
        
provider.FromXmlString(PublicKey)
;

        byte
[] inArray provider.Encrypt(bytes, false)
;
        
        
provider 
= null;
        
        return 
Convert.ToBase64String(inArray)
;
    
}

    
public string DecryptText(string 
strToDecript)
    {
        UnicodeEncoding encoding 
= new UnicodeEncoding()
;

        
RSACryptoServiceProvider provider = new RSACryptoServiceProvider()
;
        
RSACryptoServiceProvider.UseMachineKeyStore 
= false;

        
provider.FromXmlString(PrivateKey)
;

        byte
[] rgb Convert.FromBase64String(strToDecript)
;
        byte
[] bytes provider.Decrypt(rgb, false)
;

        
provider 
= null;

        return 
encoding.GetString(bytes)
;
    
}
    
}

Posted 1-9-2008 19:32 por Pedro Antonio Seixas Subutzki

Add a Comment

(requerido)  
(opcional)
(requerido)  
Remember Me?
If you can't read this number refresh your screen
Enter the numbers above:  
Powered by Community Server (Commercial Edition), by Telligent Systems