login about faq

When Decoding a given File (lagacy VB6 app) it works, butt the Resulting string Contains "Garbage" before and behind the Resulting (XML) String -- what is wrong ?

Dim ckGlobal        As New Chilkat_v9_5_0.ChilkatGlobal
Dim DeCrypt         As New Chilkat_v9_5_0.ChilkatCrypt2
Dim Cert            As New Chilkat_v9_5_0.ChilkatCert
Dim b64String       As String
Dim Success         As Long
Dim decryptedText   As String
Dim iFd             As Integer

' encodedb64.dat contains crypted data
iFd = FreeFile
Open "c:\s3c\encodedb64.dat" For Binary As #iFd
b64String = Space(LOF(iFd))
Get #iFd, 1, b64String
Close iFd

' keystore.p12 enthält das Arzt-Zertifikat
Success = ckGlobal.UnlockBundle("Hello Hello Hello")
Success = Cert.LoadPfxFile("c:\s3c\keystore.p12", "12345678")
'Success = DeCrypt.AddPfxSourceFile("c:\s3c\keystore.p12", "12345678")
Success = DeCrypt.SetDecryptCert(Cert)

DeCrypt.Charset = "us-ascii"
DeCrypt.CryptAlgorithm = "pki"
decryptedText = DeCrypt.DecryptStringENC(b64String)
' decryptedText with Leading and Trailing Garbage
' -- returns Error:
'Call DeCrypt.CkDecryptFile("c:\s3c\encodedb64.dat", "c:\s3c\encodedb64.xml")
Debug.Print DeCrypt.LastErrorText
' Remove garbage Q&D
decryptedText = Mid$(decryptedText, 50)
decryptedText = Left$(decryptedText, 2874)
MsgBox decryptedText

asked Sep 09 '15 at 05:49

maalders's gravatar image

maalders
11


Some thoughts:

Is your encrypted file indeed DER-encoded (ASN.1) PKCS#7 data in Base64? Perhaps you could post it for examination?

Does it work if you explicitly set DeCrypt.EncodingMode = "base64"?

Does it work if you use Decrypt.Charset = "unicode"?

link

answered Sep 09 '15 at 09:07

jpbro's gravatar image

jpbro ♦
1.1k2618

DeCrypt.EncodingMode = "base64" does'nt change anything Decrypt.Charset = "unicode" results in lots of ????? File Upload is not possible for me an B64 encoded String ist too long

(Sep 09 '15 at 11:12) maalders

Below ist the Base 64 decoded String to be encrypted, the fallowing is what I get when i try to Call DeCrypt.CkDecryptFile("c:s3cencodedb64.dat", "c:s3cencodedb64.xml")

ChilkatLog: CkDecryptFile: DllDate: Aug 26 2015 ChilkatVersion: 9.5.0.52 UnlockPrefix: FoooooooAD.CBX0816 Username: MA-PCNOTE:ma Architecture: Little Endian; 32-bit Language: ActiveX VerboseLogging: 0 Component successfully unlocked using purchased unlock code. inputFile: [c:s3cencodedb64.dat] outputFile: [c:s3cencodedb64.xml] decryptPkcs7: algorithm: pki Using specific decrypt certificate. certSerialNumber: 43A2825EA295ED3B certIssuerCN: KV Telematik GmbH User CA 1 Getting pre-installed private key. loadPkcs7Der: der_to_xml: ASN data length exceeds remaining number of bytes available. tag: 15 idClass: 1 bConstructed: 1 headerLen: 2 dataLen: 74 inlen: 8 Abort ASN.1 processing... recursiveDepth: 1 --der_to_xml loadPkcs7Xml: Expected oid tag for 1st child in PKCS7 --loadPkcs7Xml --loadPkcs7Der Not PKCS7 DER --decryptPkcs7 Failed to decrypt. Failed. --CkDecryptFile --ChilkatLog

MIIT0wYJKoZIhvcNAQcDoIITxDCCE8ACAQAxggF3MIIBcwIBADBbME8xJDAiBgNVBAMMG0tWIFRlbGVtYXRpayBHbWJIIFVzZXIgQ0EgMTEaMBgGA1UECgwRS1YgVGVsZW1hdGlrIEdtYkgxCzAJBgNVBAYTAkRFAghDooJeopXtOzANBgkqhkiG9w0BAQcwAASCAQBBQe5A2sXiXaWbZjF+PuZFSS/YHhYug+bVu6satUB28shvFPwTQC9Z/dhEVljT9OjnZmF+zOpkc7O9O93v8MseqTQChU4hT5ZvRWwPnOe38N3AftnS/bUqXast7Zy6sC1D8TyhRkyrh+2BhXXPIyb0OETuwnSOsWQZuuH3V5nyXuj3LdRa/SZbV30kNwWR+E86K+8p+LCeCeUeprKHaXDo/4mZibIGS6DXeFg867Y17TC2pYWVO9RJwlh0rNiHtHCwZ1wwE0RgRUV8essh1GCsyGLASpKkYY2h0UnevE0jKvSM6iCBQFUgjTQTj/gw9HfWtBXt5coo6Q/tNXqxDyvLMIIS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E17qXRhDGjtI3zBZFFhPsPDgRKTORCfA5MyeEXp3kbi2fPXMDsteGHyg5sVyuY5aM7ki5cN6efDp7A3Q5sMEfm6Jj2917Bh1VvejwqenUn6g7W+qnyK/9OOpSjcg3/nsDbNN8XUEr6p4WbXiXoLSuzSKao5R7w4hpxIUtDsXrboYpZr37kZuLd7mFfUJRzwYTuzAl8n5XjXZvXHQJ24P+/KujPSOd+GfpYkC1BaAxK0ncM3Jt1dFH+ogUbA2DVYL5doUznOW7IWlQD3OliBFI9LFAn+PD5OIN4FyC+XjC0NLMZnqQABGtgaP3Mlmb30O9heJIWZ3cwBGCPxuA9bbgqWv4IFcwwNG+jJc7GWV5Rm4SoPIlfu0ySsia69hiWL60rD1WzIEWMvSCCOj1q4ppFwCGvNanOBD+0SmKOK1oTt8dZHJlocrYE7j81rCeyowY4O21A1pp/GNM87VeZ32/wjv+gP5PluSjAJrrQJOmJ97mdbsz3AT3GXkpESYiMR00s/Lq7RcL/swvKUg+L5uISff004k8TSRFPHg0YXErT35m2apMxFZ2r9eW9On3SOIU3Q/g06FFEDMe6U0npsEeHUpfi9AGDQQpyMZmdt+DO4O/O6PL/i4vifmObUcSELlr16YvioCrfDmjdxo/kLSDqn3PDQEK30AwMuyAN69unjlo6uPjkEf6ikpBBqFTH61DCxX27lcCYlNkiFblsQhrAoRJQQgHasBoiZSsjhULjHvajEx9PqCoNAWs1sOSuI1RobKBM//92lqGzo0D8kxBZjNwQVBLIQjDVJ9tJc1Zx7Cm+aj9kXV7lsglneau3O16Z2LgFK0kPPXp63

link

answered Sep 09 '15 at 11:21

maalders's gravatar image

maalders
11

I see now that you are a customer with non-expired support. When this is the case, please let me know by sending email to support@chilkatsoft.com. It is good to post to the Forum, but it's not an official support channel. If I know the question is from a customer with valid support, then I will respond on the forum the same as in email. :-)

I will investigate this problem..

link

answered Sep 09 '15 at 12:12

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Encryption is a deterministic, computational, transformation of input bytes to output bytes that resemble random data. There is no format to the output. With PKCS7, what gets encrypted is an ASN.1 structure that contains the actual data. The output, as I just said, is non-structure random-looking bytes.

The reverse process is to decrypt. We start with the random-looking bytes, decrypt, and the result (if successful) should be the original ASN.1, from which the actual data is extracted. When the decryption occurs using an invalid key or the wrong key, the result will be garbage (it will not be ASN.1). There is no way to know this unless we try to parse it as ASN.1 -- and this is the error you see: "ASN data length exceeds..."

I noticed in your code snippet above, you are not checking the success/failure return values for many calls: UnlockBundle, LoadPfxFile, etc. Make sure you do. If any of these methods failed, you want to catch and fix that failure first.

If you still have trouble, I need an actual dataset (.p12 + .dat) to reproduce the issue.

link

answered Sep 09 '15 at 12:32

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×35
×33
×7

Asked: Sep 09 '15 at 05:49

Seen: 1,890 times

Last updated: Sep 09 '15 at 12:32

powered by OSQA