Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 13, 2012 05:14 AM by dileepkumarkalva
0 Points
7 Posts
Apr 06, 2012 10:06 AM|LINK
Hello,
I have a different requirement, pdf is encrypted by using a key and that encrypted pdf will be sent to client, when anybody opens
that pdf, it asks for key, if right key applied pdf should be decrypted and displayed.
I have used RijndaelManaged Algorithm for encrypting pdf file, pdf is getting encrypted, but when i double click on that
encrypted pdf its not asking for key. It should ask for key and pdf will be decrypted and will be opened.
I have two programs , one for encryption , one for decryption. I am successfully encrypting and decrypting by using those
prg's. but for decrypting i cannot use program, when we double click on file then only decryption program runs and check
for right key, should be decrypted.
I have been really searching for this specific thing for the past 48 hours. I did not find any solution.
Please help me out from this problem...
This is my code to encrypt pdf by using a key
UnicodeEncoding UE = new UnicodeEncoding(); byte[] key = UE.GetBytes(password);
string cryptFile = outputFile;
FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);
RijndaelManaged RMCrypto = new RijndaelManaged();
CryptoStream cs = new CryptoStream(fsCrypt, RMCrypto.CreateEncryptor(key, key), CryptoStreamMode.Write);
FileStream fsIn = new FileStream(inputFile, FileMode.Open);
int data; while ((data = fsIn.ReadByte()) != -1) cs.WriteByte((byte)data);
fsIn.Close(); cs.Close(); fsCrypt.Close();
This is my decryption program.
FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);
CryptoStream cs = new CryptoStream(fsCrypt, RMCrypto.CreateDecryptor(key, key), CryptoStreamMode.Read);
FileStream fsOut = new FileStream(outputFile, FileMode.Create);
int data; while ((data = cs.ReadByte()) != -1) fsOut.WriteByte((byte)data);
fsOut.Close(); cs.Close(); fsCrypt.Close();
Thanks in Advance...
Apr 10, 2012 06:35 AM|LINK
hi dev-guru,
Thanx for advise.
your above lines of code will only do password protection for pdf, but it will not encrypt text in pdf.
I want something which encrypts data in pdf file using a password or key, and any body can view that pdf provided same key.
any advises are greatly welcome
Dileep kumar.
Apr 13, 2012 05:14 AM|LINK
Hi,
I have earlier used ITextSharp.dll , but i didnot get the solution. I finally findout solution in someother way.
string outputFile = @"E:\javascript6secure.pdf"; string inputFile = @"E:\javascript6.pdf";
using (Stream input = new FileStream(inputFile, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (Stream output = new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.None)) { PdfReader reader = new PdfReader(input); PdfEncryptor.Encrypt(reader, output, true, "secret", "secret", PdfWriter.ENCRYPTION_AES_128);
} }
As you said ITextSharp.DLL is used here. Pdf is converted and even search engines cannot access these pdf's meta data.
dileepkumark...
0 Points
7 Posts
how to decrypt pdf by using a key
Apr 06, 2012 10:06 AM|LINK
Hello,
I have a different requirement, pdf is encrypted by using a key and that encrypted pdf will be sent to client, when anybody opens
that pdf, it asks for key, if right key applied pdf should be decrypted and displayed.
I have used RijndaelManaged Algorithm for encrypting pdf file, pdf is getting encrypted, but when i double click on that
encrypted pdf its not asking for key. It should ask for key and pdf will be decrypted and will be opened.
I have two programs , one for encryption , one for decryption. I am successfully encrypting and decrypting by using those
prg's. but for decrypting i cannot use program, when we double click on file then only decryption program runs and check
for right key, should be decrypted.
I have been really searching for this specific thing for the past 48 hours. I did not find any solution.
Please help me out from this problem...
This is my code to encrypt pdf by using a key
UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);
string cryptFile = outputFile;
FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);
RijndaelManaged RMCrypto = new RijndaelManaged();
CryptoStream cs = new CryptoStream(fsCrypt,
RMCrypto.CreateEncryptor(key, key),
CryptoStreamMode.Write);
FileStream fsIn = new FileStream(inputFile, FileMode.Open);
int data;
while ((data = fsIn.ReadByte()) != -1)
cs.WriteByte((byte)data);
fsIn.Close();
cs.Close();
fsCrypt.Close();
This is my decryption program.
UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);
FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);
RijndaelManaged RMCrypto = new RijndaelManaged();
CryptoStream cs = new CryptoStream(fsCrypt,
RMCrypto.CreateDecryptor(key, key),
CryptoStreamMode.Read);
FileStream fsOut = new FileStream(outputFile, FileMode.Create);
int data;
while ((data = cs.ReadByte()) != -1)
fsOut.WriteByte((byte)data);
fsOut.Close();
cs.Close();
fsCrypt.Close();
Thanks in Advance...
dileepkumark...
0 Points
7 Posts
Re: how to decrypt pdf by using a key
Apr 10, 2012 06:35 AM|LINK
hi dev-guru,
Thanx for advise.
your above lines of code will only do password protection for pdf, but it will not encrypt text in pdf.
I want something which encrypts data in pdf file using a password or key, and any body can view that pdf provided same key.
any advises are greatly welcome
Dileep kumar.
dileepkumark...
0 Points
7 Posts
Re: how to decrypt pdf by using a key
Apr 13, 2012 05:14 AM|LINK
Hi,
I have earlier used ITextSharp.dll , but i didnot get the solution. I finally findout solution in someother way.
string outputFile = @"E:\javascript6secure.pdf";
string inputFile = @"E:\javascript6.pdf";
using (Stream input = new FileStream(inputFile, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (Stream output = new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.None))
{
PdfReader reader = new PdfReader(input);
PdfEncryptor.Encrypt(reader, output, true, "secret", "secret", PdfWriter.ENCRYPTION_AES_128);
}
}
As you said ITextSharp.DLL is used here. Pdf is converted and even search engines cannot access these pdf's meta data.