pgpainless/src/main/java/org/pgpainless/pgpainless/PGPainless.java

81 lines
2.9 KiB
Java
Raw Normal View History

/*
* Copyright 2018 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.pgpainless;
2018-06-02 21:21:35 +02:00
2018-06-05 01:30:58 +02:00
import java.io.IOException;
import org.bouncycastle.openpgp.PGPException;
import org.pgpainless.pgpainless.algorithm.CompressionAlgorithm;
import org.pgpainless.pgpainless.algorithm.SymmetricKeyAlgorithm;
import org.pgpainless.pgpainless.decryption_verification.DecryptionBuilder;
import org.pgpainless.pgpainless.encryption_signing.EncryptionBuilder;
2018-07-02 20:09:45 +02:00
import org.pgpainless.pgpainless.key.KeyRingReader;
import org.pgpainless.pgpainless.key.generation.KeyRingBuilder;
import org.pgpainless.pgpainless.symmetric_encryption.SymmetricEncryptorDecryptor;
2018-06-02 21:21:35 +02:00
public class PGPainless {
public static KeyRingBuilder generateKeyRing() {
return new KeyRingBuilder();
}
public static EncryptionBuilder createEncryptor() {
return new EncryptionBuilder();
}
public static DecryptionBuilder createDecryptor() {
return new DecryptionBuilder();
}
2018-07-02 20:09:45 +02:00
/**
* Read some existing OpenPGP key ring.
*
* @return KeyRingReader which offers reading operations
*/
public static KeyRingReader readKeyRing() {
return new KeyRingReader();
2018-06-05 01:30:58 +02:00
}
/**
* Encrypt some data symmetrically using OpenPGP and a password.
* The resulting data will be uncompressed and integrity protected.
*
* @param data input data.
* @param password password.
* @return symmetrically OpenPGP encrypted data.
* @throws IOException IO is dangerous.
* @throws PGPException PGP is brittle.
*/
public static byte[] encryptWithPassword(byte[] data, char[] password, SymmetricKeyAlgorithm algorithm) throws IOException, PGPException {
return SymmetricEncryptorDecryptor.symmetricallyEncrypt(data, password,
algorithm, CompressionAlgorithm.UNCOMPRESSED);
}
/**
* Decrypt some symmetrically encrypted data using a password.
* The data is suspected to be integrity protected.
*
* @param data symmetrically OpenPGP encrypted data.
* @param password password.
* @return decrypted data.
* @throws IOException IO is dangerous.
* @throws PGPException PGP is brittle.
*/
public static byte[] decryptWithPassword(byte[] data, char[] password) throws IOException, PGPException {
return SymmetricEncryptorDecryptor.symmetricallyDecrypt(data, password);
}
2018-06-02 21:21:35 +02:00
}