Class KeySerializer


  • public final class KeySerializer
    extends java.lang.Object
    Collection of tools to serialize / deserialize PGP types.

    There is no way to serialize / deserialize a PGPPrivateKey on its own, you have to pair it with the public key.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.bouncycastle.openpgp.PGPKeyPair deserializeKeyPair​(byte[] serialized)
      Deserialize a PGPKeyPair
      static org.bouncycastle.openpgp.PGPPublicKey deserializePublicKey​(byte[] serialized)
      Deserialize a PGPPublicKey
      static java.lang.String deserializeString​(byte[] serialized)
      Deserializes a string
      static byte[] serializeKeyPair​(org.bouncycastle.openpgp.PGPKeyPair keyPair)
      Serialize a PGPKeyPair
      static byte[] serializePublicKey​(org.bouncycastle.openpgp.PGPPublicKey publicKey)
      Serialize a PGPPublicKey
      static byte[] serializeString​(java.lang.String key)
      Serializes a string
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • serializePublicKey

        public static byte[] serializePublicKey​(org.bouncycastle.openpgp.PGPPublicKey publicKey)
                                         throws java.io.IOException
        Serialize a PGPPublicKey

        The reason we're not using PGPPublicKey.getEncoded() is to use ArmoredOutputStream.

        Throws:
        java.io.IOException
      • deserializePublicKey

        public static org.bouncycastle.openpgp.PGPPublicKey deserializePublicKey​(byte[] serialized)
                                                                          throws java.io.IOException
        Deserialize a PGPPublicKey
        Throws:
        java.io.IOException
      • serializeString

        public static byte[] serializeString​(java.lang.String key)
        Serializes a string
      • deserializeString

        public static java.lang.String deserializeString​(byte[] serialized)
        Deserializes a string
      • serializeKeyPair

        public static byte[] serializeKeyPair​(org.bouncycastle.openpgp.PGPKeyPair keyPair)
                                       throws java.io.IOException,
                                              org.bouncycastle.openpgp.PGPException
        Serialize a PGPKeyPair

        Use this to serialize a PGPPrivateKey as well (pairing it with the corresponding PGPPublicKey), as private keys can't be serialized on their own.

        Throws:
        java.io.IOException
        org.bouncycastle.openpgp.PGPException
      • deserializeKeyPair

        public static org.bouncycastle.openpgp.PGPKeyPair deserializeKeyPair​(byte[] serialized)
                                                                      throws java.io.IOException,
                                                                             org.bouncycastle.openpgp.PGPException
        Deserialize a PGPKeyPair
        Throws:
        java.io.IOException
        org.bouncycastle.openpgp.PGPException