WALTER | Workable Algorithms for Location-aware Transmission, Encryption Response

PGPManaged..::..Encrypt Method (String, String)

Encrypts the specified plain text.

Namespace:  Walter.Cypher.PGP
Assembly:  Walter.Cypher (in Walter.Cypher.dll)

Syntax


[MethodImplAttribute]
public string Encrypt(
	string plainText,
	string publicKey
)

Parameters

plainText
Type: String
The plain text.
publicKey
Type: String
The public key.

Return Value

Returns an encrypted text using the public key that can only be decrypted using the private key

Exceptions


ExceptionCondition
ArgumentNullExceptionplainText
ArgumentNullExceptionpublicKey

Examples


PGP encryption is safe and allows 2 parties to encrypt data without having to share passwords. You should store your private key locally in a secure location, perhaps even using an encrypt the file using a password, see Cypher class for this.
C#
var keyGen = new PGPKeyGenerator();

   var keyRing = keyGen.GenerateKeys(PGPKeySize.Key2048);
   var pgp = new PGPManaged();
   var largeTextFile = JsonConvert.SerializeObject(keyRing);
   var secure = pgp.Encrypt(largeTextFile, keyRing.PublicKey);

   var copy = pgp.Decrypt(secure, keyRing.PrivateKey);

   Assert.AreEqual(largeTextFile, copy);