/* * [SignAndEncrypt.java] * * Summary: Digitally sign a message, then encrypt it. * * Copyright: (c) 2004-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.4 2006-03-05 reformat with IntelliJ and add Javadoc. */ package com.mindprod.transporter; import java.io.IOException; import java.io.Serializable; /** * Digitally sign a message, then encrypt it. *

* Using compression, and base64u armouring. *

* See Transporter.java for example of use. * * @author Roedy Green, Canadian Mind Products * @version 1.4 2006-03-05 reformat with IntelliJ and add Javadoc. * @since 2004-06-08 */ public final class SignAndEncrypt extends Wrap { /** * helper for signing */ protected final Sign signer; /** * helper for encrypting */ private final Encrypt encrypter; /** * constructor. * * @param senderPrivateKey sender's private key * @param receiverPublicKey receiver's public key */ public SignAndEncrypt( PrivateKey senderPrivateKey, PublicKey receiverPublicKey ) { super(); signer = new Sign( senderPrivateKey ); encrypter = new Encrypt( receiverPublicKey ); } /** * The whole enchilada. Wraps object for sending via CIA Post, serialised, compressed, signed, encrypted and base64u * armoured. Does not build parm=value. * * @param o Object to wrap for sending. * * @return base64u-encoded string to send. * @throws IOException */ public String wrap( Serializable o ) throws IOException { return armour( encrypter.encrypt( signer .sign( compress( serialize( o ) ) ) ) ); } } // end SignAndEncrypt