protected static void ValidateSymmetricEncryptor(ISymmetricEncryptor encryptor) { var cipherKR = encryptor.Encrypt(Encoding.Unicode.GetBytes(PlainTextKR)); var clearKR = Encoding.Unicode.GetString(encryptor.Decrypt(cipherKR)); Assert.AreEqual(PlainTextKR, clearKR); var cipherUS = encryptor.Encrypt(Encoding.Unicode.GetBytes(PlainTextUS)); var clearUS = Encoding.Unicode.GetString(encryptor.Decrypt(cipherUS)); Assert.AreEqual(PlainTextUS, clearUS); }
/// <summary> /// 암호화된 문자열을 복원합니다. /// </summary> /// <param name="encryptor"></param> /// <param name="encryptedText"></param> /// <returns></returns> public static string DecryptString(this ISymmetricEncryptor encryptor, string encryptedText) { if (encryptedText.IsEmpty()) { return(string.Empty); } return(encryptor.Decrypt(encryptedText.Base64Decode()).ToText(StringTool.DefaultEncoding)); }
public void EncryptAndDecrypt() { var key = "8C662D023DD014B483AC66546573C9FA64185F1704E6B610F4AAA0DE30CE9016"; string text = "this is my ßecrͼt teݨt"; var encrypted = _encryptor.Encrypt(text, key); Assert.Equal(text, _encryptor.Decrypt(encrypted, key)); }
/// <summary> /// 대칭형 암호화 알고리즘을 이용하여, <paramref name="format"/>형태의 <paramref name="cipherText"/>를 복호화합니다. /// </summary> /// <param name="encryptor">대칭형 암호화 인스턴스</param> /// <param name="cipherText">암호화된 정보</param> /// <param name="format">암호화된 정보의 문자열 형식(Base64|HexDecimal)</param> /// <returns>복화화된 원본 문자열</returns> public static string DecryptString(this ISymmetricEncryptor encryptor, string cipherText, EncryptionStringFormat format = EncryptionStringFormat.HexDecimal) { if (cipherText.IsEmpty()) { return(cipherText); } var plainBytes = encryptor.Decrypt(cipherText.StringToBytes(format)); return(Encoding.Unicode.GetString(plainBytes).Trim('\0')); }
/// <summary> /// 비동기 방식으로 암호화된 데이터를 복원합니다. /// </summary> /// <param name="encryptor"></param> /// <param name="cipher"></param> /// <returns></returns> public static Task <byte[]> DecriptAsync(this ISymmetricEncryptor encryptor, byte[] cipher) { return(Task.Factory.StartNew(() => encryptor.Decrypt(cipher))); }
/// <summary> /// 암호화된 스트림을 복원합니다. /// </summary> /// <param name="encryptor"></param> /// <param name="stream"></param> /// <returns></returns> public static Stream DecryptStream(this ISymmetricEncryptor encryptor, Stream stream) { return(new MemoryStream(encryptor.Decrypt(stream.ToBytes()))); }
/// <summary> /// 대칭형 암호화 알고르즘을 이용하여 <paramref name="cipherBytes"/>를 복호화 합니다. /// </summary> /// <param name="encryptor">대칭형 암호화 인스턴스</param> /// <param name="cipherBytes">암호화된 정보</param> /// <returns>복호화된 정보</returns> public static byte[] DecryptBytes(this ISymmetricEncryptor encryptor, byte[] cipherBytes) { return(encryptor.Decrypt(cipherBytes)); }
/// <summary> /// 대칭형 암호화 알고리즘을 이용하여, <paramref name="cipherStream"/>을 복호화한 스트림을 반환합니다. /// </summary> /// <param name="encryptor">대칭형 암호화 인스턴스</param> /// <param name="cipherStream">암호화된 정보를 가진 스트림</param> /// <returns>복호화된 정보를 가진 스트림</returns> public static Stream DecryptString(this ISymmetricEncryptor encryptor, Stream cipherStream) { cipherStream.ShouldNotBeNull("cipherStream"); return(new MemoryStream(encryptor.Decrypt(cipherStream.ToBytes()))); }