Home › Forums › ActiveX components › Xceed Zip for ActiveX & x64 › Invalid Password
-
AuthorPosts
-
#42472 |
What’s wrong in the code below:
public string compactaXceedStr(ref byte[] objCadeia)
{
string strRet = “”;
object oRet = new object();
xcdCompressionError oXretError = new xcdCompressionError();XceedCompression oX = new XceedCompression();
oX.EncryptionPassword = “bit”;
object oCadeiaMsg = (object)objCadeia;
oXretError = oX.Compress(ref oCadeiaMsg, out oRet, true);
if (oXretError == xcdCompressionError.xceSuccess)
{
byte[] dBytes = (byte[])oRet;
strRet = System.Text.Encoding.Default.GetString(dBytes);
}
else
strRet = “erro”;return strRet;
}public string desCompactaXceedStr(ref byte[] objCadeia)
{
string strRet = “”;
object oRet = new object();
xcdCompressionError oXretError = new xcdCompressionError();
XceedCompression oX = new XceedCompression();
oX.EncryptionPassword = “bit”;
object oCadeiaMsg = (object)objCadeia;
oXretError = oX.Uncompress(ref oCadeiaMsg, out oRet, true);
if (oXretError == xcdCompressionError.xceSuccess)
{
byte[] dBytes = (byte[])oRet;
strRet = System.Text.Encoding.Default.GetString(dBytes);
}
else
strRet = “erro”;return strRet;
}I compress the word “teste” and get this retun:” ´)ímw¶þ2*œP×pîv¥&ƒ ” but when i uncompress i got this error: invalida password. Wheres is the problem with this code??
Imported from legacy forums. Posted by Fabio (had 1642 views)
Hi Fabio,
Using System.Text.Encoding.Default to convert the compressed bytes into a string is a mistake. Not all byte combinations are allowed in Unicode. As such, there is no guarantee that the conversion back to bytes will yield the original compressed byte data.
We would suggest using another conversion like Convert.ToBase64String()/FromBase64String().
For example:
static void F33108()
{
XceedCompression oX = new XceedCompressionClass();
oX.License( “<your license key>” );xcdCompressionError oXretError = new xcdCompressionError();
string strRet;
string data = “teste”;
byte[] objCadeia = System.Text.Encoding.Default.GetBytes( data );object oRet;
oX.EncryptionPassword = “bit”;
object oCadeiaMsg = ( object ) objCadeia;
oXretError = oX.Compress( ref oCadeiaMsg, out oRet, true );
if( oXretError == xcdCompressionError.xceSuccess )
{
byte[] dBytes = ( byte[] ) oRet;
//strRet = System.Text.Encoding.Default.GetString( dBytes );
strRet = Convert.ToBase64String( dBytes );
}
else
strRet = “erro”;//objCadeia = System.Text.Encoding.Default.GetBytes( strRet );
objCadeia = Convert.FromBase64String( strRet );
oCadeiaMsg = ( object ) objCadeia;
oXretError = oX.Uncompress( ref oCadeiaMsg, out oRet, true );
if( oXretError == xcdCompressionError.xceSuccess )
{
byte[] dBytes = ( byte[] ) oRet;
strRet = System.Text.Encoding.Default.GetString( dBytes );
}
else
strRet = “erro”;
}Imported from legacy forums. Posted by Diane [Xceed] (had 384 views)
Hi, thanks for the example, but i got another problem, the return in the byte arrays is “t\0e\0s\0t\0e\0” and when i convert to a string i got only the “t” not “teste”.
Do you know why?? How can i resolve this when i convert the byte array to string?
Ats,
Fabio Magalhaes
Imported from legacy forums. Posted by Fabio (had 277 views)
Thanks i resolve this using:
bytRet = (byte[])oDadoDesCompactado;
strRet = System.Text.Encoding.Unicode.GetString(bytRet);After the Uncompress method, and the result was sucess i got the “teste” return.
Imported from legacy forums. Posted by Fabio (had 374 views)
Hi Diane Lafontaine you help me with the last problem about how to
CONVERT to string the return of a compress method, i had done what you
described and the results in my test were successful .But now i
am using my apps and i got an error, let me explain the apps: I have a
client app and a server app, my client app was done in C# and i use the
following compress method:public string compactaXceedStr(ref string dados, string senha = “”)
{
string strRet = “”;
object oDadoCompactado;
object oDadoOriginal;
byte[] bytRet;
xcdCompressionError oXceedretorno = new xcdCompressionError();
XceedCompression oXceed = new XceedCompression();oDadoOriginal = (object)dados;
oXceed.EncryptionPassword = senha;
oXceedretorno = oXceed.Compress(ref oDadoOriginal, out oDadoCompactado, true);if (oXceedretorno == xcdCompressionError.xceSuccess)
{
bytRet = (byte[])oDadoCompactado;
strRet = Convert.ToBase64String(bytRet);
}
else
strRet = oXceed.GetErrorDescription(Convert.ToInt16(oXceedretorno));
return strRet;
}My server app was done in visual basic 6, and my uncompress method in vb6 is:
Public Function XCeedDescompStr(ByRef varCadeia As Variant, Optional strSenha As String = “”) As Variant
Dim xcdZip As New XceedCompression, varData As Variant, lngRetCode As xcdCompressionError
If strSenha <> “” Then xcdZip.EncryptionPassword = strSenha
lngRetCode = xcdZip.Uncompress(varCadeia, varData, True)
If lngRetCode = xceSuccess Then
XCeedDescompStr = StrConv(varData, vbUnicode)
Else
Err.Raise lngRetCode, Err.Source, xcdZip.GetErrorDescription(lngRetCode), Err.HelpFile, Err.HelpContext
End IfEnd Function
But when my client send the compressed data to the server, the server report this error:
1004 Descrição:Invalid password provided for for the data to uncompress.
Can you help me solve this problem?
When
i use a client and sever both C# or vb6 the compress and uncompress
work fine, but when i use my real scenario, client c# e server vb6 i
got only error results .Imported from legacy forums. Posted by Fabio (had 366 views)
Hi Fabio,
The compressed data or the password is corrupted when you convert it for transport between the client and the server.
We need to distinguish between the two. If you run your test without using a password, do you still get errors?
Imported from legacy forums. Posted by Diane [Xceed] (had 352 views)
Without password i got te same “Invalid password provided for for the data to uncompress.”
Imported from legacy forums. Posted by Fabio (had 348 views)
Hi Fabio,
Then this means your data is corrupted.
The way you handle your input data
seems to have a problem. You need to fix that. If your input data is a string, then you need to
convert the string to a byte array in a consistent manner. A way that both C#
and VB6 can manipulate.The same with the compressed data. In the code you
show us, you convert his compressed data to a Base64 string. Yet your
decompression code just feeds the data to our Uncompress() as is. Has the data
been converted from Base64 to its original byte array? If not, the decompression
will only see corrupt data of course.Once the data has been
decompressed, we go back to previous note above, a way that both C# and VB6 can
manipulate.Your decompression code uses StrConv(varData, vbUnicode) to
convert your decompressed byte array to a VB6 unicode string. What sort of byte
data does StrConv() expect? Unicode 8? Unicode 16? You need to find out and make
sure that at the start of your compression code in C#, you produce a byte array
from your input string that matches what StrConv() expects..NET can
convert a System.String to a byte array using several different Unicode
encodings. The global object System.Text.Encoding.UTF8 produces Unicode 8 data.
System.Text.Encoding.Unicode produces Unicode 16 data.Imported from legacy forums. Posted by Fawzi [Xceed] (had 1733 views)
-
AuthorPosts
- You must be logged in to reply to this topic.