public GetAsymmetricPublicKeyResponse GetAsymmetricPublicKey() { GetAsymmetricPublicKeyResponse publicKeyResponse = new GetAsymmetricPublicKeyResponse(); try { AsymmetricKeyPairGenerationResult asymmetricKeyPair = _cryptographyInfrastructureService.GenerateAsymmetricKeys(); Guid messageId = Guid.NewGuid(); publicKeyResponse.MessageId = messageId; publicKeyResponse.PublicKeyXml = asymmetricKeyPair.PublicKeyOnlyXml; _asymmetricKeyRepositoryFactory.Create().Add(messageId, asymmetricKeyPair); } catch (Exception ex) { publicKeyResponse.Exception = ex; } return(publicKeyResponse); }
public ProcessSecretMessageResponse ProcessSecretMessage(ProcessSecretMessageRequest processSecretMessageRequest) { ProcessSecretMessageResponse response = new ProcessSecretMessageResponse(); try { AsymmetricKeyPairGenerationResult asymmetricKeyInStore = _asymmetricKeyRepositoryFactory.Create().FindBy(processSecretMessageRequest.MessageId); _asymmetricKeyRepositoryFactory.Create().Remove(processSecretMessageRequest.MessageId); String decryptedPublicKey = _asymmetricCryptoService.DecryptCipherText(processSecretMessageRequest.EncryptedPublicKey , asymmetricKeyInStore); String decryptedMessage = _symmetricCryptoService.Decrypt(processSecretMessageRequest.SymmetricEncryptionArgs.InitialisationVector , decryptedPublicKey, processSecretMessageRequest.SymmetricEncryptionArgs.CipherText); response.SecretMessageProcessResult = string.Concat("Message received and deciphered: ", decryptedMessage); } catch (Exception ex) { response.SecretMessageProcessResult = string.Concat("Exception during the message decryption process: ", ex.Message); response.Exception = ex; } return(response); }
public void Add(Guid messageId, AsymmetricKeyPairGenerationResult asymmetricKeyPair) { _asymmetricKeyPairs[messageId] = asymmetricKeyPair; }
static void Main(string[] args) { IAsymmetricCryptographyService ser = new RsaCryptographyService(); AsymmetricKeyPairGenerationResult keyPair = ser.GenerateAsymmetricKeys(); }