pontoNETpt
A comunidade PontoNetPT está direccionada a todos os programadores que trabalhem com a plataforma .NET.
Entrar
|
Inscrever
|
Ajuda
Home
Blogs
Media
Forums
Wikis
Groups
Pedro Antonio Seixas Subutzki
»
Criptografia com RSA e Base64
Criptografia com RSA e Base64
Pedro Antonio Seixas Subutzki
Início
Syndication
RSS for Posts
Atom
RSS for Comments
Email Notifications
Go
Recent Posts
Criptografia com RSA e Base64
Criptografia... MD5!
Validando AGÊNCIA ou CONTA do banco BRADESCO
Resgatando e alterando uma imagem via URL
Resgatando conteúdo externo utilizando a classe System.Net.WebClient
Archives
Setembro 2008 (1)
Maio 2008 (1)
Agosto 2006 (3)
Junho 2006 (1)
Abril 2006 (1)
Março 2006 (2)
Janeiro 2006 (1)
Dezembro 2005 (3)
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
Name:
(requerido)
Website:
(opcional)
Comments
(requerido)
Remember Me?
Enter the numbers above: