私はinfopathの添付ファイルの暗号化されたエンコードされた文字列を受け取り、解読するc#コードを持っています。これは以下のコードである:Attachment Decryption System.FormatException:Base-64 char配列または文字列の長さが無効です
private int fileSize;
private int attachmentNameLength;
private string attachmentName;
private byte[] decodedAttachment;
/// <summary>
/// Accepts the Base64 encoded string
/// that is the attachment.
/// </summary>
public InfoPathAttachmentDecoder(string theBase64EncodedString)
{
**byte[] theData = Convert.FromBase64String(theBase64EncodedString);** //This line throws a System.FormatException: Invalid length for a Base-64 char array or string.
using (MemoryStream ms = new MemoryStream(theData))
{
BinaryReader theReader = new BinaryReader(ms);
DecodeAttachment(theReader);
}
}
private void DecodeAttachment(BinaryReader theReader)
{
//Position the reader to obtain the file size.
byte[] headerData = new byte[FIXED_HEADER];
headerData = theReader.ReadBytes(headerData.Length);
fileSize = (int)theReader.ReadUInt32();
attachmentNameLength = (int)theReader.ReadUInt32() * 2;
byte[] fileNameBytes = theReader.ReadBytes(attachmentNameLength);
//InfoPath uses UTF8 encoding.
Encoding enc = Encoding.Unicode;
attachmentName = enc.GetString(fileNameBytes, 0, attachmentNameLength - 2);
decodedAttachment = theReader.ReadBytes(fileSize);
}
public void SaveAttachment(string saveLocation)
{
string fullFileName = saveLocation;
if (!fullFileName.EndsWith(Path.DirectorySeparatorChar.ToString()))
{
fullFileName += Path.DirectorySeparatorChar;
}
fullFileName += attachmentName;
if (File.Exists(fullFileName))
File.Delete(fullFileName);
FileStream fs = new FileStream(fullFileName, FileMode.CreateNew);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(decodedAttachment);
bw.Close();
fs.Close();
}
public string Filename
{
get { return attachmentName; }
}
public byte[] DecodedAttachment
{
get { return decodedAttachment; }
}
}
ライン・バイト[] theData = Convert.FromBase64String(theBase64EncodedString)。ベース64の配列または文字列に対して、システム書式例外の無効な長さをスローします。
1.コード内の暗号化があります。 2. Base64でエンコードされた文字列は、4バイトの倍数でなければなりません。 3.問題のあるBase64文字列はどこにありますか? – zaph
x0lGQRQAAAABAAAAAAAAAH8IAAALAAAAdABlAHMAdAAwADEALgB0AHgAdAAAAHVzaW5nIFN5c3RlbTsNCnVzaW5nIFN5c3RlbS5Db2xsZWN0aW9ucy5HZW5lcmljOw0KdXNpbmcgU3lzdGVtLkxpbnE7DQp1c2luZyBTeXN0ZW0uV2ViOw0KdXNpbmcgU3lzdGVtLldlYi5NdmM7DQoNCm5hbWVzcGFjZSBNb3ZpZXNBcHAuQ29udHJvbGxlcnM –
**は誰もがそれを見るウィルの質問に追加informatiin **を追加して、暗号化は例えばInfoPathで行われ、私は、アップロードされた文書が暗号化されています。その後、このコメントを削除します。 – zaph