|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.didisoft.pgp.bc.BaseLib
com.didisoft.pgp.inspect.PGPInspectLib
public class PGPInspectLib
Provides methods for inspecting OpenPGP files and streams.
Copyright (c) DidiSoft Ltd 2012.
www.didisoft.com
Field Summary |
---|
Fields inherited from class com.didisoft.pgp.bc.BaseLib |
---|
BOUNCY_CASTLE_PROVIDER |
Constructor Summary | |
---|---|
PGPInspectLib()
|
Method Summary | |
---|---|
boolean |
isPBEEncrypted(java.io.InputStream dataStream)
Checks is a given OpenPGP stream encrypted with a password. |
boolean |
isPBEEncrypted(java.lang.String fileName)
Checks is a given OpenPGP file encrypted with a password. |
boolean |
isPublicKeyEncrypted(java.io.InputStream dataStream)
Checks is a given OpenPGP stream encrypted with a public key. |
boolean |
isPublicKeyEncrypted(java.lang.String fileName)
Checks is a given OpenPGP file encrypted with a public key. |
boolean |
isSignedOnly(java.io.InputStream dataStream)
Checks is a given OpenPGP archive stream signed only |
boolean |
isSignedOnly(java.lang.String fileName)
Checks is a given OpenPGP archive signed only |
SignatureItem[] |
listDetachedSignatureFile(java.lang.String detachedSignatureFile)
Lists information for an OpenPGP detached signature file |
SignatureItem[] |
listDetachedSignatureStream(java.io.InputStream detachedSignatureStream)
Lists information for an OpenPGP detached signature stream |
long[] |
listEncryptionKeyIds(java.io.InputStream dataStream)
Returns the Key Id's that have encrypted a given OpenPGP archive |
long[] |
listEncryptionKeyIds(java.lang.String fileName)
Returns the Key Id's that have encrypted a given OpenPGP archive |
ContentItem[] |
listOpenPGPFile(java.lang.String signedFileName)
Lists the contents of an OpenPGP signed file Example: |
ContentItem[] |
listOpenPGPFile(java.lang.String fileName,
java.lang.String privateKeyFileName,
java.lang.String privateKeyPassword)
Lists the contents of an OpenPGP encrypted file Example: |
ContentItem[] |
listOpenPGPStream(java.io.InputStream signedStream)
Lists the contents of an OpenPGP signed stream Example: |
ContentItem[] |
listOpenPGPStream(java.io.InputStream encryptedStream,
java.io.InputStream privateKeyStream,
java.lang.String privateKeyPassword)
Lists the contents of an OpenPGP encrypted stream Example: |
long[] |
listSigningKeyIds(java.io.InputStream dataStream)
Returns the Key Id's that have signed a given OpenPGP signed only archive |
long[] |
listSigningKeyIds(java.io.InputStream encryptedStream,
java.io.InputStream privateKeyStream,
java.lang.String privateKeyPassword)
Returns a list of the Key Id's for the key(s) that have encrypted a given OpenPGP archive |
long[] |
listSigningKeyIds(java.lang.String dataFileName)
Returns the Key Id's that have signed a given OpenPGP signed only archive |
long[] |
listSigningKeyIds(java.lang.String dataFileName,
java.lang.String privateKeyFileName,
java.lang.String privateKeyPassword)
Returns the Key Id's that have signed a given OpenPGP archive |
Methods inherited from class com.didisoft.pgp.bc.BaseLib |
---|
extractPrivateKey, isForVerification, replaceAll |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PGPInspectLib()
Method Detail |
---|
public boolean isPublicKeyEncrypted(java.lang.String fileName) throws java.io.IOException, NonPGPDataException
fileName
- source file to be checked
java.io.IOException
- I/O error
NonPGPDataException
- if the source file is not an OpenPGP archive at allpublic boolean isPublicKeyEncrypted(java.io.InputStream dataStream) throws java.io.IOException, NonPGPDataException
dataStream
- OpenPGP source stream to be checked
java.io.IOException
- I/O error
NonPGPDataException
- if the source is not an OpenPGP archive at allpublic boolean isPBEEncrypted(java.lang.String fileName) throws java.io.IOException, NonPGPDataException
fileName
- source file to be checked
java.io.IOException
- I/O error
NonPGPDataException
- if the source file is not an OpenPGP archive at allpublic boolean isPBEEncrypted(java.io.InputStream dataStream) throws java.io.IOException, NonPGPDataException
dataStream
- source stream to be checked
java.io.IOException
- I/O error
NonPGPDataException
- if the source file is not an OpenPGP archive at allpublic long[] listEncryptionKeyIds(java.lang.String fileName) throws java.io.IOException, NonPGPDataException
fileName
- encrypted OpenPGP archive
java.io.IOException
- I/O error
NonPGPDataException
- if the source file is not an OpenPGP archive at allpublic long[] listEncryptionKeyIds(java.io.InputStream dataStream) throws java.io.IOException, NonPGPDataException
dataStream
- encrypted OpenPGP stream
java.io.IOException
- I/O error
NonPGPDataException
- if the source is not an OpenPGP archive at allpublic SignatureItem[] listDetachedSignatureFile(java.lang.String detachedSignatureFile) throws java.io.IOException, NonPGPDataException
detachedSignatureFile
- OpenPGP detached signature file
SignatureItem
objects
java.io.IOException
- I/O error
NonPGPDataException
- if the source is not an OpenPGP detached signature
Example:
PGPLib pgp = new PGPLib(); // should the output be in ASCII or binary format boolean asciiArmour = true; pgp.detachedSignFile("myfile.txt", "my_private_key.asc", "my_private_key password", "detached.sig", asciiArmour); PGPInspectLib inspect = new PGPInspectLib(); com.didisoft.pgp.inspect.SignatureItem[] signatures = inspect.listDetachedSignatureFile("detached.sig"); for (SignatureItem sig : signatures) { System.out.println("Signednature produced with Key Id: " + sig.getKeyId()); System.out.println("Signednature created on: " + sig.getSignatureTime()); }
public SignatureItem[] listDetachedSignatureStream(java.io.InputStream detachedSignatureStream) throws java.io.IOException, NonPGPDataException
detachedSignatureFile
- OpenPGP detached signature stream
SignatureItem
objects
java.io.IOException
- I/O error
NonPGPDataException
- if the source is not an OpenPGP detached signaturepublic long[] listSigningKeyIds(java.lang.String dataFileName) throws PGPException, java.io.IOException
dataFileName
- OpenPGP signed only data
java.io.IOException
- I/O error
PGPException
- general OpenPGP error
NonPGPDataException
- if the source file is not an OpenPGP archive at all
FileIsEncryptedException
- if the source file is not only signed but also encryptedpublic long[] listSigningKeyIds(java.io.InputStream dataStream) throws PGPException, java.io.IOException
dataStream
- OpenPGP signed only input stream
java.io.IOException
- I/O error
PGPException
- general OpenPGP error
NonPGPDataException
- if the source is not an OpenPGP archive at all
FileIsEncryptedException
- if the source is not only signed but also encryptedpublic long[] listSigningKeyIds(java.lang.String dataFileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword) throws PGPException, java.io.IOException
encryptedStream
- OpenPGP encrypted dataprivateKeyStream
- private key data in order to decrypt the file and inspect the signaturesprivateKeyPassword
- private key
java.io.IOException
- I/O error
PGPException
- OpenPGP decryption error
NonPGPDataException
- if the source file is not an OpenPGP archive at all
WrongPrivateKeyException
- if the source file was not encrypted with this private key. Extends PGPException
WrongPasswordException
- if the password for this private key is misspelled. Extends PGPExceptionpublic boolean isSignedOnly(java.lang.String fileName) throws PGPException, java.io.IOException
fileName
- encrypted OpenPGP archive
java.io.IOException
- I/O error
PGPException
- OpenPGP decryption error
NonPGPDataException
- if the source file is not an OpenPGP archive at allpublic boolean isSignedOnly(java.io.InputStream dataStream) throws PGPException, java.io.IOException
dataStream
- input stream obtained from a OpenPGP archive
java.io.IOException
- I/O error
PGPException
- OpenPGP error
NonPGPDataException
- if the source is not an OpenPGP archive at allpublic long[] listSigningKeyIds(java.io.InputStream encryptedStream, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword) throws PGPException, java.io.IOException
encryptedStream
- OpenPGP encrypted dataprivateKeyStream
- private key data in order to decrypt the file and inspect the signaturesprivateKeyPassword
- private key
java.io.IOException
- I/O error
PGPException
- OpenPGP decryption error
NonPGPDataException
- if the source file is not an OpenPGP archive at all
WrongPrivateKeyException
- if the input stream was not encrypted with this private key. Extends PGPException
WrongPasswordException
- if the password for this private key is misspelled. Extends PGPExceptionpublic ContentItem[] listOpenPGPFile(java.lang.String fileName, java.lang.String privateKeyFileName, java.lang.String privateKeyPassword) throws PGPException, java.io.IOException
import com.didisoft.pgp.*; import com.didisoft.pgp.inspect.*; public class InspectEncryptedFile { public static void main(String[] args) throws Exception { // Inspect the content of the encrypted file without decrypting PGPInspectLib inspectLib = new PGPInspectLib(); String privateKey = "DataFiles/private.key"; String privateKeyPassword = "changeit"; String encryptedFile = "DataFiles/encrypted.pgp"; ContentItem[] files = inspectLib.listOpenPGPFile(encryptedFile, privateKey, privateKeyPassword); for (int i = 0; i < files.length; i++) { System.out.print(files[i].getFileName()); System.out.print(files[i].isDirectory() ? "" : " "); System.out.println(files[i].getModificationDate()); } } }
encryptedFileName
- OpenPGP encrypted file (absolute or relative path)privateKeyFileName
- Private Key file name (absolute or relative path)privateKeyPassword
- Private key password
ContentItem
elements contained in the specified OpenPGP file
java.io.IOException
- If a file/stream operation throws an exception
PGPException
- if a problem has occurred while decrypting file
WrongPrivateKeyException
- if the file was not encrypted with this private key.
WrongPasswordException
- if the password for this private key is wrong.
NonPGPDataException
- if the input file is not a valid OpenPGP encrypted filepublic ContentItem[] listOpenPGPFile(java.lang.String signedFileName) throws PGPException, java.io.IOException
import com.didisoft.pgp.*; import com.didisoft.pgp.inspect.*; public class InspectEncryptedFile { public static void main(String[] args) throws Exception { // Inspect the content of the encrypted file without decrypting PGPInspectLib inspectLib = new PGPInspectLib(); String encryptedFile = "DataFiles/encrypted.pgp"; ContentItem[] files = null; if (inspectLib.isSignedOnly(encryptedFile)) { files = inspectLib.listOpenPGPStream(encryptedFile); } else { String privateKey = "DataFiles/private.key"; String privateKeyPassword = "changeit"; files = inspectLib.listOpenPGPFile(encryptedFile, privateKey, privateKeyPassword); } for (int i = 0; i < files.length; i++) { System.out.print(files[i].getFileName()); System.out.print(files[i].isDirectory() ? "" : " "); System.out.println(files[i].getModificationDate()); } } }
signedFileName
- OpenPGP encrypted file (absolute or relative path)
ContentItem
elements contained in the specified OpenPGP file
java.io.IOException
- if a file/stream operation throws an exception
PGPException
- if a problem has occurred while decrypting file
FileIsEncryptedException
- if the supplied data is encrypted
WrongPrivateKeyException
- if the file was not encrypted with this private key.
WrongPasswordException
- if the password for this private key is wrong.
NonPGPDataException
- if the input file is not a valid OpenPGP encrypted filepublic ContentItem[] listOpenPGPStream(java.io.InputStream encryptedStream, java.io.InputStream privateKeyStream, java.lang.String privateKeyPassword) throws PGPException, java.io.IOException
import java.io.*; import com.didisoft.pgp.*; import com.didisoft.pgp.inspect.*; public class InspectEncryptedStream { public static void main(String[] args) throws Exception { // Inspect the content of an encrypted stream without decrypting PGPInspectLib inspectLib = new PGPInspectLib(); InputStream privateKey = new FileInputStream("DataFiles/private.key"); String privateKeyPassword = "changeit"; InputStream encryptedStream = new BufferedInputStream(new FileInputStream("DataFiles/encrypted.pgp")); ContentItem[] files = inspectLib.listOpenPGPStream(encryptedStream, privateKey, privateKeyPassword); for (int i = 0; i < files.length; i++) { System.out.print(files[i].getFileName()); System.out.print(files[i].isDirectory() ? "" : " "); System.out.println(files[i].getModificationDate()); } privateKey.close(); encryptedStream.close(); } }
encryptedStream
- OpenPGP encrypted or signed streamprivateKeyStream
- Private key file streamprivateKeyPassword
- Private key password
ContentItem
elements contained in the specified OpenPGP file
java.io.IOException
- If a file/stream operation throws an exception
PGPException
- if a problem has occurred while decrypting file
WrongPrivateKeyException
- if the file was not encrypted with this private key.
WrongPasswordException
- if the password for this private key is wrong.
NonPGPDataException
- if the input file is not a valid OpenPGP encrypted filepublic ContentItem[] listOpenPGPStream(java.io.InputStream signedStream) throws PGPException, java.io.IOException
import java.io.*; import com.didisoft.pgp.*; import com.didisoft.pgp.inspect.*; public class InspectSignedStream { public static void main(String[] args) throws Exception { // Inspect the content of an encrypted stream without decrypting PGPInspectLib inspectLib = new PGPInspectLib(); String pgpFile = "DataFiles/encrypted.pgp"; InputStream encryptedStream = new FileInputStream(pgpFile); ContentItem[] files = null; if (inspectLib.isSignedOnly(pgpFile)) { files = inspectLib.listOpenPGPStream(encryptedStream); } else { InputStream privateKey = new FileInputStream("DataFiles/private.key"); String privateKeyPassword = "changeit"; files = inspectLib.listOpenPGPStream(encryptedStream, privateKey, privateKeyPassword); } for (int i = 0; i < files.length; i++) { System.out.print(files[i].getFileName()); System.out.print(files[i].isDirectory() ? "" : " "); System.out.println(files[i].getModificationDate()); } privateKey.close(); encryptedStream.close(); } }
signedStream
- OpenPGP signed stream
ContentItem
elements contained in the specified OpenPGP file
java.io.IOException
- If a file/stream operation throws an exception
PGPException
- if a problem has occurred while decrypting file
WrongPrivateKeyException
- if the data was not encrypted with this private key.
WrongPasswordException
- if the password for this private key is wrong.
FileIsEncryptedException
- if the supplied data is encrypted
NonPGPDataException
- if the data is not a valid OpenPGP encrypted message
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |