2022-07-04 20:12:42 +02:00
|
|
|
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package org.pgpainless.certificate_store;
|
|
|
|
|
|
|
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
|
|
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
|
|
|
import org.pgpainless.PGPainless;
|
2022-08-12 15:04:54 +02:00
|
|
|
import pgp.certificate_store.certificate.Certificate;
|
|
|
|
import pgp.certificate_store.certificate.Key;
|
2022-07-04 20:12:42 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
public class KeyFactory {
|
|
|
|
|
2022-08-24 13:24:05 +02:00
|
|
|
public static Key keyFromSecretKeyRing(PGPSecretKeyRing secretKeyRing, Long tag) throws IOException {
|
|
|
|
byte[] bytes = secretKeyRing.getEncoded();
|
|
|
|
PGPPublicKeyRing publicKeyRing = PGPainless.extractCertificate(secretKeyRing);
|
|
|
|
Certificate certificate = CertificateFactory.certificateFromPublicKeyRing(publicKeyRing, tag);
|
|
|
|
return new Key(bytes, certificate, tag);
|
2022-07-04 20:12:42 +02:00
|
|
|
}
|
|
|
|
}
|