@@ -78,6 +78,7 @@ private PGPEncryptingStream(final KeyringConfig config, final PGPAlgorithmSuite
78
78
* @param keySelectionStrategy selection strategy
79
79
* @param armor armor the file (true) or use binary.
80
80
* @param encryptTo encrypt to
81
+ * @param textMode simulates GnuPG's {@code --textmode} flag
81
82
*
82
83
* @return stream where plaintext gets written into
83
84
*
@@ -93,7 +94,8 @@ public static OutputStream create(final KeyringConfig config,
93
94
final OutputStream cipherTextSink ,
94
95
final KeySelectionStrategy keySelectionStrategy ,
95
96
final boolean armor ,
96
- final Set <PGPPublicKey > encryptTo )
97
+ final Set <PGPPublicKey > encryptTo ,
98
+ final boolean textMode )
97
99
throws IOException , PGPException , NoSuchAlgorithmException , NoSuchProviderException {
98
100
99
101
requireNonNull (config , "callback must not be null" );
@@ -109,7 +111,7 @@ public static OutputStream create(final KeyringConfig config,
109
111
}
110
112
111
113
final PGPEncryptingStream encryptingStream = new PGPEncryptingStream (config , algorithmSuite );
112
- encryptingStream .setup (cipherTextSink , signingUid , encryptTo , keySelectionStrategy , armor );
114
+ encryptingStream .setup (cipherTextSink , signingUid , encryptTo , keySelectionStrategy , armor , textMode );
113
115
return encryptingStream ;
114
116
}
115
117
@@ -122,6 +124,7 @@ public static OutputStream create(final KeyringConfig config,
122
124
* @param pubEncKeys the pub enc keys
123
125
* @param keySelectionStrategy key selection strategy (for signatures)
124
126
* @param armor if OutputStream should be "armored", that means base64 encoded
127
+ * @param textMode simulates GnuPG's {@code --textmode} flag
125
128
*
126
129
* @throws IOException Signals that an I/O exception has occurred.
127
130
* @throws PGPException the pGP exception
@@ -134,7 +137,8 @@ private void setup(final OutputStream cipherTextSink,
134
137
@ Nullable final String signingUid ,
135
138
final Set <PGPPublicKey > pubEncKeys ,
136
139
final KeySelectionStrategy keySelectionStrategy ,
137
- final boolean armor ) throws
140
+ final boolean armor ,
141
+ final boolean textMode ) throws
138
142
IOException , PGPException {
139
143
isDoSign = signingUid != null ;
140
144
@@ -186,7 +190,7 @@ private void setup(final OutputStream cipherTextSink,
186
190
new BcPGPContentSignerBuilder (pgpSec .getPublicKey ().getAlgorithm (),
187
191
algorithmSuite .getHashAlgorithmCode ().getAlgorithmId ()));
188
192
189
- signatureGenerator .init (PGPSignature .BINARY_DOCUMENT , pgpPrivKey );
193
+ signatureGenerator .init (textMode ? PGPSignature . CANONICAL_TEXT_DOCUMENT : PGPSignature .BINARY_DOCUMENT , pgpPrivKey );
190
194
191
195
final Iterator <?> userIDs = pgpSec .getPublicKey ().getUserIDs ();
192
196
if (userIDs .hasNext ()) {
@@ -208,7 +212,7 @@ private void setup(final OutputStream cipherTextSink,
208
212
209
213
encryptionDataStreamGenerator = new PGPLiteralDataGenerator ();
210
214
encryptionDataStream = encryptionDataStreamGenerator
211
- .open (compressionStream , PGPLiteralData .BINARY , "" , new Date (), new byte [1 << 16 ]);
215
+ .open (compressionStream , textMode ? PGPLiteralData . TEXT : PGPLiteralData .BINARY , "" , new Date (), new byte [1 << 16 ]);
212
216
}
213
217
214
218
@ Override
@@ -268,4 +272,4 @@ public void close() throws IOException {
268
272
isClosed = true ;
269
273
}
270
274
}
271
- }
275
+ }
0 commit comments