How to add digital signature to pdf in Ruby? - ruby-on-rails

I am generating pdf using wicked_pdf and I am also using prawntable for pdfs which needs to be password protected. Since wicked pdf doesnt supports password protected pdf generation.
Is there any way to add a digital signature which is in .pfx format to pdf.?

Passwording pdf files vs digitally signing them
Passwording a pdf file encrypts the file. You will need to find a pdf library/toolkit to do that for you. If you can't find one with a ruby API, then you can call it as a command from ruby. The latter is not as elegant but works fine. (Be sure to catch and handle errors.)
Digitally signing a pdf is completely different than encryption. The result of signing is a pdf with one or more digital signatures. You use either a library to sign a file locally or, for a more dependable system, sign the file via a dedicated appliance that also holds the signer's private key and certificate.
Unlike password protection/encryption, anyone who receives a digitally signed pdf file can read the file's content. The digital signatures provide the relying party (the recipient) with assurances about:
the identity of the person who signed the file
the integrity of the file (confirming that it wasn't changed since signing)
the non-reputability of the file (confirming that the signer can't claim that they hadn't signed the file)
An important issue is that having a signer's private key on the file system of a regular computer/server is not secure enough to provide any guarantee against repudiation by the signer--she could truthfully say that there is no way to assure that her "signature" was not forged by un-authorized use of the pfx file.

The Origami library has a very basic support for PDF digital signatures and there is sample code for this at https://github.com/gdelugre/origami/blob/master/examples/signature/signature.rb.

Related

How to support password protection to a document similar to keynote in iOS

Is there any apple API to support encryption of a document similar to keynote application(.key file) or in general how to support encryption to entire document.
I can't encrypt entire folder because in iCloud scenario small change will trigger the entire document to upload looks like i am missing something.
I just tried to see how the files are encrypted in keynote. In the below image left side is document without password and other one is with password.
Thanks
I think there is no straight forward way to encrypt entire document we have to do file by file.

Create PGP key to use with ObjectivePGP in iOS app

I'm making an application that needs encrypt/decrypt GPG messages but it needs generate its own keys (public/private).
I'm using ObjectivePGP and it works great, but it doesn't generate the keys by itself (or I don't know how to do it), so I need to generate it via command line with gpg or some online tools.
My question is: Is there some way to create these keys inside my app? Maybe some framework with appstore friendly license.
Notes:
I've tried with UNNetPGP, but it doesn't work when I try to encrypt messages with public keys generated by other applications or decrypt messages encrypted by these applications. I have even tried just use UNNetPGP just to generate the keys and import them to ObjectivePGP, but I receive messages like "Decrypt key doesn't exist" or similar (this doesn't happen when I use another keys).

Encrypting or protecting files stored in iOS app's NSDocumentsDirectory

I have a custom requirement in one of my products and I need to protect or encrypt files that are stored inside the NSDocumentsDirectory folder. Even if these documents are mailed (The app has the ability to mail documents) to some other person , he or she will not be able to open this document without using my app (I will be using open in functionality of email attachments). So basically only the application can access all these documents and without the app the documents should be mere junk. IS there any way to do it, or has any one done something before.
I also saw this but could not get a complete idea.
If you want a quick and easy method for data that doesn't need serious security, just zip the files with a fixed password.
ZipArchive is a good library for this.
For a more serious approach, check iOS - Protecting files with a custom encryption key?
The other post you mentioned works on the concept of password protecting the files, I had encountered the same issue that was for my custom defined files in which our team, encoded the contents of the file on random locations, and saved it.
Only our Application could decode it correctly as we had the key :)
It was a windows application, It would work here also.

Object File format on iOS (getting SHA512 hash of installed app)

Is there a way that I can know the hash all or part of an iOS app's executable file, prior to submitting my app for approval?
Would it be possible to include a magic constant in my app, so I could use its approximate position as a starting point for taking a SHA512 hash of most of the executable file? I would like to add additional executable verification mechanisms to my app.
EDIT: After some searching on the Apple Developer site, I've run across the Mach-O File Format specification.
Apple encrypts portions of the executable file, so any file hash prior to submission is likely to be invalid on a distributed app.
What you might be able to do is hash/checksum portions of the app as it executes in memory, by getting live function pointers and using them as start addresses.

Blackberry signature tool - invalid private key

A couple of months after installing successfully the BlackBerry signature key for signing my application, I have lost my private key. How can I retrieve it?
I have already sent an email to BlackBerry developers' support, but they're really slow in replying.
Search your hard-drive or trash-bin for sigtool.* :
You need to find sigtool.csk and sigtool.db. If you can find these files you can copy them to your Components\bin folder. For example:
C:\eclipses\BB1.1.2\plugins\net.rim.ejde.componentpack6.0.0_6.0.0.29\components\bin
Or you can use the Import Key Feature of the Blackberry Plugin and point it to these files.
If you can't find these files, then you need TechSupport to resend you the three CSI files for creating your keys. Note, after you create a key-set with these csi files they are useless, so you can't use them to recreate new keys later.
I suggest backing up the sigtool files after you find/recreate them.
Good Luck mate!

Resources