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="text"></param> /// <returns></returns> public static string EncryptString(this ISymmetricEncryptor encryptor, string text) { if (text.IsEmpty()) { return(string.Empty); } return(encryptor.Encrypt(text.ToBytes(StringTool.DefaultEncoding)).Base64Encode()); }
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)); }
public virtual void EncryptSecret() { Secret.EncryptedText = _secretEncryptor.Encrypt(UnencryptedSecret, EncryptionKey); Secret.EncryptionType = EncryptorMapping.BackwardMapping[_secretEncryptor.GetType().AssemblyQualifiedName]; _logger.LogDebug($"Secret encrypted with {Secret.EncryptionType}"); }
/// <summary> /// 스트림을 암호화 합니다. /// </summary> /// <param name="encryptor"></param> /// <param name="stream"></param> /// <returns></returns> public static Stream EncryptStream(this ISymmetricEncryptor encryptor, Stream stream) { return(new MemoryStream(encryptor.Encrypt(stream.ToBytes()))); }
/// <summary> /// 비동기 방식으로 데이터를 암호화 합니다. /// </summary> /// <param name="encryptor"></param> /// <param name="plainBytes"></param> /// <returns></returns> public static Task <byte[]> EncryptAsync(this ISymmetricEncryptor encryptor, byte[] plainBytes) { return(Task.Factory.StartNew(() => encryptor.Encrypt(plainBytes))); }
/// <summary> /// 대칭형 암호화 알고리즘을 이용하여 <paramref name="plainBytes"/>를 암호화 합니다. /// </summary> /// <param name="encryptor">대칭형 암호화 인스턴스</param> /// <param name="plainBytes">원본 정보</param> /// <returns>암호화된 정보</returns> public static byte[] EncryptBytes(this ISymmetricEncryptor encryptor, byte[] plainBytes) { return(encryptor.Encrypt(plainBytes)); }
/// <summary> /// 대칭형 암호화 알고리즘을 이용하여, <paramref name="plainStream"/>을 암호화하여 스트림으로 반환합니다. /// </summary> /// <param name="encryptor">대칭형 암호화 인스턴스</param> /// <param name="plainStream">원본 스트림</param> /// <returns>암호화된 스트림</returns> public static Stream EncryptStream(this ISymmetricEncryptor encryptor, Stream plainStream) { plainStream.ShouldNotBeNull("plainStream"); return(new MemoryStream(encryptor.Encrypt(plainStream.ToBytes()))); }