Java clearsign
The clear text signature OpenPGP message format is designed to sign text messages. The original message is kept as is and an additional signature is appended. This way the recipient can still read the original message without special software.
Clear signed messages are verified just like ordinary signed data.
The examples below demonstrate how to achieve this with DidiSoft OpenPGP Library for Java.
Clearsign string message with private key located in file
Clearsign file with private key located in file
Clearsign string message with private key located in file
This example shows how to clear sign a text message. The signature algorithm is specified explicitly in contrast to the standard sign method.
import com.didisoft.pgp.HashAlgorithm; import com.didisoft.pgp.PGPLib; public class ClearSignString { public static void main(String[] args) throws Exception{ // create an instance of the library PGPLib pgp = new PGPLib(); String message = "The quick brown fox jumps."; // clear sign String clearSignedMessage = pgp.clearSignString(message, "private.asc", "private key pass", HashAlgorithm.SHA256); } }
Clearsign file with private key located in file
This example demonstrates how to cleartext sign a file. The result file will contain the original file contents intact and an additional signature.
import com.didisoft.pgp.HashAlgorithm; import com.didisoft.pgp.PGPLib; public class ClearSignFile { public static void main(String[] args) throws Exception{ // create an instance of the library PGPLib pgp = new PGPLib(); // clear sign pgp.clearSignFile("INPUT.txt", "private.asc", "private key pass", HashAlgorithm.SHA256, "OUTPUT.sig.txt"); } }