예제 #1
0
 /**
  * Encrypt plain text and return ASCII-armored text.
  *
  * @param recipients array of keys to encrypt to
  * @param plain the GnuPGData to be encrypted
  * @return String encrypted data in ASCII-armored text
  */
 public String encryptToAscii(GnuPGKey[] recipients, GnuPGData plain) {
   long l = getInternalRepresentation();
   boolean previous = gpgmeGetArmor(l);
   gpgmeSetArmor(l, true);
   GnuPGData cipher = createDataObject();
   encrypt(recipients, plain, cipher);
   final String ret = cipher.toString();
   cipher.destroy();
   if (previous == false) // maintain the original ASCII-Armor state
   gpgmeSetArmor(l, false);
   return ret;
 }
예제 #2
0
 /**
  * Encrypt plain data and return encrypted data in binary form.
  *
  * @param recipients array of keys to encrypt to
  * @param plain the GnuPGData to be encrypted
  * @return String encrypted data in ASCII-armored text
  */
 public byte[] encryptToBinary(GnuPGKey[] recipients, GnuPGData plain) {
   long l = getInternalRepresentation();
   boolean previous = gpgmeGetArmor(l);
   gpgmeSetArmor(l, true);
   GnuPGData cipher = createDataObject();
   encrypt(recipients, plain, cipher);
   ByteArrayOutputStream baos = new ByteArrayOutputStream(plain.size());
   BufferedOutputStream out = new BufferedOutputStream(baos, 8192);
   try {
     cipher.write(out);
   } catch (IOException e) {
     e.printStackTrace();
   }
   cipher.destroy();
   if (previous == false) // maintain the original ASCII-Armor state
   gpgmeSetArmor(l, false);
   return baos.toByteArray();
 }
예제 #3
0
 /**
  * Tell the gpg engine to use ASCII armor. Please check GPG/GPGME for documentation if you don't
  * know what this means. (Try 'man gpg' on the command line and look for 'armor')
  *
  * @param state set true if results should be ASCII armored, set false if binary
  */
 public void setArmor(boolean state) {
   gpgmeSetArmor(getInternalRepresentation(), state);
 }