안녕 얘들이 좀 도와주십시오 무효, 난이 오류가 계속 :길이
Length of the data to decrypt is invalid.
내가 잘못하고있는 중이 야 무엇을?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Cryptography;
using System.IO;
namespace inChargeAES
{
public class inChargeCrypto : IinChargeAES
{
public inChargeCrypto() {}
public String inChargeEncrypt(String plaintext, byte[] encryptionKey, byte[] initializationVector)
{
if (plaintext == null || plaintext.Length <= 0)
{
throw new ArgumentNullException("plaintext");
}
if(encryptionKey == null || encryptionKey.Length <= 0){
throw new ArgumentNullException("encryptionKey");
}
if(initializationVector == null || initializationVector.Length <= 0){
throw new ArgumentNullException("initializationVector");
}
byte[] encryptedText;
using(RijndaelManaged rjManage = new RijndaelManaged())
{
rjManage.Key = encryptionKey;
rjManage.IV = initializationVector;
rjManage.Mode = CipherMode.CBC;
//rjManage.Padding = PaddingMode.None;
ICryptoTransform iTransformer = rjManage.CreateEncryptor(rjManage.Key, rjManage.IV);
using(MemoryStream memStream = new MemoryStream())
{
using(CryptoStream cEncryptStream = new CryptoStream(memStream, iTransformer, CryptoStreamMode.Write))
{
using(StreamWriter encryptStreamWriter = new StreamWriter(cEncryptStream))
{
encryptStreamWriter.Write(plaintext);
}
encryptedText = memStream.ToArray();
}
}
}
return Convert.ToBase64String(encryptedText);
}
public String inChargeDecrypt(byte[] cipher, byte[] encryptionKey, byte[] initializationVector)
{
if (cipher == null || cipher.Length <= 0){
throw new ArgumentNullException("cipher");
}
if (encryptionKey == null || encryptionKey.Length <= 0){
throw new ArgumentNullException("encryptionKey");
}
if (initializationVector == null || initializationVector.Length <= 0){
throw new ArgumentNullException("initializationVector");
}
String decryptedText = null;
using (RijndaelManaged rijManage = new RijndaelManaged())
{
rijManage.Key = encryptionKey;
rijManage.IV = initializationVector;
rijManage.Mode = CipherMode.CBC;
rijManage.Padding = PaddingMode.None;
ICryptoTransform iTranformation = rijManage.CreateDecryptor(rijManage.Key, rijManage.IV);
using(MemoryStream memStream = new MemoryStream(cipher))
{
using(CryptoStream cDecryptorStream = new CryptoStream(memStream, iTranformation, CryptoStreamMode.Read))
{
using (StreamReader decryptReader = new StreamReader(cDecryptorStream))
{
decryptedText = decryptReader.ReadToEnd(); //Exception Is Thrown
}
//memStream.Read(cipher, 0, cipher.Length);
}
}
}
return decryptedText;
}
}
}
패딩하면 암호화하고 해독 같은 값으로 할 필요가 [] 바이트로 다시 base64로 문자열을 변환하는 실수를하지 않은 가정. –
당신의 방법은 암호화 나 복호화에 패딩이없는 나를 위해 잘 작동합니다. – Kevin