How to decode a base64 PDF without encryption in TCL? - pdf

Using Tcl in a integration suite called Cloverleaf, the programming language used is TCL.
The command I'm using for it is correct set dcpdf [::base64 -mode decode $pdf] the packege is called earlier in the code, the problem is that after the code base64 is decoded and we try to open the file it requires a password, there is no passwork inhereit to the file, is there a arg to the decode comand that stops this issue?

Related

JSZip reports missing bytes when reading back previously uploaded zip file

I am working on a webapp where the user provides an image file-text sequence. I am compressing the sequence into a single ZIP file uisng JSZip.
On the server I simply use PHP move_uploaded_file to the desired location after having checked the file upload error status.
A test ZIP file created in this way can be found here. I have downloaded the file, expanded it in Windows Explorer and verified that its contents (two images and some HTML markup in this instance) are all present and correct.
So far so good. The trouble begins when I try to fetch that same ZIP file and expand it using JSZip.loadAsync which consistently reports Corrupted zip: missing 210 bytes. My PHP code for squirting back the ZIP file is actually pretty simple. Shorn of the various security checks I have in place the essential bits of that code are listed below
if (file_exists($file))
{
ob_clean();
readfile($file);
http_response_code(200);
die();
} else http_response_code(399);
where the 399 code is interpreted in my webapp as a need to create a new resource locally instead of trying to read existing resource data. The trouble happens when I use the result text (on an HTTP response of 200) and feed it to JSZip.loadAsync.
What am I doing wrong here? I assume there is something too naive about the way I am using readfile at the PHP end but I am unable to figure out what that might be.
What we set out to do
Attempt to grab a server-side ZIP file from JavaScript
If it does not exist send back a reply (I simply set a custom HTTP response code of 399 and interpret it) telling the client to go prepare its own new local copy of that resource
If it does exist send back that ZIP file
Good so far. However, reading the existent ZIP file into PHP and sending it back does not make sense + is fraught with problems. My approach now is to send back an http_response_code of 302 which the client interprets as being an instruction to "go get that ZIP for yourself directly".
At this point to get the ZIP "directly" simply follow the instructions in this tutorial on MDN.

Swagger UI endpoint doesn't return UTF-8 encoded response using ABP.IO

I am using abp framework as in http://www.abp.io
Now, executing this endpoint /api/abp/application-configuration using Swagger UI returns a json results see snippet below
Not sure why the results isn't UTF-8 encoded, I am expecting Mâle but got M�le
your help is appreciated
Answer:
Open the json file ie fr.json
Change the encoding to UTF-8 , you can use VS or Notepad++
Save the file
reopen the file to ensure change is done

Webmethods - Retrieve PDF file from SFTP and encode

I am new to webmethods and need some guidance. I am tasked to read the PDF document from SFTP server and base64 encode it. I have managed to GET the file from SFTP location and now struggling to encode it. Below is the code snippet to read the file:
INVOKE pub.client.sftp:login
INVOKE pub.client.sftp:cd
INVOKE pub.client.sftp:ls
INVOKE pub.client.sftp:get
MAP
I later modified the code to include base64 encoding, no output is produced. Code is shown below:
INVOKE pub.client.sftp:login
INVOKE pub.client.sftp:cd
INVOKE pub.client.sftp:ls
INVOKE pub.client.sftp:get
INVOKE pub.string:base64Encode
MAP
when i debug the code, it executes SFTP GET and stops. No information about encoding.
Please guide me to achieve this requirement. Thank you for your help in advance.
Try something like this,
after sftp:get, invoke the pub.io:streamToBytes and then invoke pub.string:base64Encode
Don't forget to map field in pipeline.
The pub.string:base64Encode expect a byte[] Input, you can try to convert the stream to byte[] with pub.io:streamToBytes

Extract and recomprise PDF file using Origami

This is regarding Origami, the Ruby tool for exploring PDF files at http://esec-lab.sogeti.com/pages/Origami
By way of example I am trying to open a PDF file, extract it and then rewrite the original PDF. This is the complete code I am trying to use to accomplish this:
hg clone https://code.google.com/p/origami-pdf/
cd origami-pdf/
rake
cd ..
curl 'http://www.ada.gov/hospcombrprt.pdf' -o hospcombrprt.pdf
origami-pdf/bin/pdf2ruby -x hospcombrprt.pdf
mv hospcombrprt.pdf hospcombrprtORIG.pdf
cd hospcombrprt
ruby hospcombrprt.rb # THIS STEP PRODUCES ERRORS
bc hospcombrprt.pdf ../hospcombrprtORIG.pdf || echo FAILED
However this produces the following error:
/Users/williamentriken/Developer/origami-pdf/lib/origami/page.rb:75:in `pages': Invalid page tree (Origami::InvalidPDFError)
from /Users/williamentriken/Developer/origami-pdf/lib/origami/pdf.rb:689:in `compile'
from /Users/williamentriken/Developer/origami-pdf/lib/origami/pdf.rb:233:in `save'
from hospcombrprt.rb:189:in `<main>'
Has anyone else had success in performing this operation using this library and could you please share?
Original Post:
I played around with the library for a while, but I kept getting errors and minor bugs, such as replicated pages and missing pages...
...you should read the authors comment about the limits of using the Origami library.
I recommend the combine_pdf gem, it's great for simple pdf manipulations, such as merging, stamping and the like.
update:
I looked at the specific PDF file and it might be an issue related to an unsupported PDF version.
The http://www.ada.gov/hospcombrprt.pdf file is encrypted with a type 4 encryption, which according to the PDF standard, starting with PDF 1.5, is:
"(PDF 1.5) The security handler defines the use of encryption and decryption in the document, using the rules specified by the CF, StmF, and StrF entries."
The encryption uses AES v.2, which is limited to PDF 1.6 and above:
"AESV2 (PDF 1.6) The application shall ask the security handler for the encryption key and shall implicitly decrypt data with "Algorithm 1: Encryption of data using the RC4 or AES algorithms", using the AES algorithm in Cipher Block Chaining (CBC) mode with a 16-byte block size and an initialization vector that shall be randomly generated and placed as the first 16 bytes in the stream or string."
So, Even if the decryption code is written in, the way to apply that code might not be known due to the way the PDF file is structured...
...It might be better to start with simple PDF files and then patch anything that isn't supported just yet.

.scr file and APDU

I am using JCard sim, java card version 2.2.2 and I want to know how the .scr file is associated with the .java file. (the java card simulator on NetBeans IDE. I am not using an actual smartcard).
If someone can provide me with some useful links on how these two files are related, I would greatly appreciate it.
I have looked through the following links, but they were not specifically helpful in illustrating how I can modify the .scr file in association with my .java file
C H A P T E R 5 - Converting Java Class Files
How to write a Java Card applet: A developer's guide - JavaWorld
Basically what I am trying to do is create a test applet (without the need of .scr files to send and receive APDUs by my other files)
- I want to be able to read APDU which contains the the parameters for a function in my process method
- That function will then create another APDU as its output, which another function will read as one of it's parameters
As far as I understand, the .scr file is used to send command APDUs that is read by the applet, but there is no way to write to the .scr file.
How can I create my own .java test file that sends and receives APDUs instead of relying on the .scr?
I can provide more details of what my code looks, if absolutely required.
Thanks
You can communicate with the simulator using the method described in the quick start guide of jCardSim. It is also described how to select an Applet using the correct AID in there. The inherited process(APDU) method will receive any APDU send using the methods described in the quick start guide, starting with the SELECT by NAME APDU (INS = A4). After that it is normal APDU processing.