001 // Copyright (C) 2002 IAIK 002 // https://jce.iaik.tugraz.at 003 // 004 // Copyright (C) 2003 - 2025 Stiftung Secure Information and 005 // Communication Technologies SIC 006 // https://sic.tech 007 // 008 // All rights reserved. 009 // 010 // Redistribution and use in source and binary forms, with or without 011 // modification, are permitted provided that the following conditions 012 // are met: 013 // 1. Redistributions of source code must retain the above copyright 014 // notice, this list of conditions and the following disclaimer. 015 // 2. Redistributions in binary form must reproduce the above copyright 016 // notice, this list of conditions and the following disclaimer in the 017 // documentation and/or other materials provided with the distribution. 018 // 019 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 020 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 021 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 022 // ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 023 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 024 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 025 // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 026 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 027 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 028 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 029 // SUCH DAMAGE. 030 031 // Copyright (C) 2002 IAIK 032 // https://sic.tech/ 033 // 034 // Copyright (C) 2003 - 2025 Stiftung Secure Information and 035 // Communication Technologies SIC 036 // https://sic.tech/ 037 // 038 // All rights reserved. 039 // 040 // This source is provided for inspection purposes and recompilation only, 041 // unless specified differently in a contract with IAIK. This source has to 042 // be kept in strict confidence and must not be disclosed to any third party 043 // under any circumstances. Redistribution in source and binary forms, with 044 // or without modification, are <not> permitted in any case! 045 // 046 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 047 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 048 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 049 // ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 050 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 051 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 052 // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 053 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 054 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 055 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 056 // SUCH DAMAGE. 057 // 058 // $Header: /IAIK-CMS/current/src/demo/smime/ecc/SimpleSMimeV4EdDemo.java 5 12.02.25 17:59 Dbratko $ 059 // $Revision: 5 $ 060 // 061 062 package demo.smime.ecc; 063 064 import demo.DemoSMimeUtil; 065 import demo.DemoUtil; 066 import demo.cms.ecc.ECCDemoUtil; 067 import demo.cms.ecc.keystore.CMSEccKeyStore; 068 import iaik.asn1.structures.AlgorithmID; 069 import iaik.utils.KeyAndCertificate; 070 import iaik.x509.X509Certificate; 071 072 /** 073 * This class demonstrates the usage of the IAIK S/MIME implementation. It shows how to create 074 * signed and/or (authenticated) encrypted S/MIMEv4 messages using Ed keys and how to parse them 075 * and verify the signatures and decrypt the content, respectively. 076 * <p> 077 * This demo uses one set of cryptographic algorithms. A demo that uses several combinations of algorithms 078 * is shown in {@link SMimeV4EccDemo SMimeV4EccDemo}. 079 * <p> 080 * Additionally to <code>iaik_cms.jar</code> you also must have 081 * <code>iaik_jce_(full).jar</code> (IAIK-JCE, <a href = 082 * "https://sic.tech/products/core-crypto-toolkits/jca-jce/" target="_blank"> 083 * https://sic.tech/products/core-crypto-toolkits/jca-jce/</a>), 084 * and <code>iaik_eccelarate.jar</code> (IAIK-ECCelerate<sup><small>TM</small></sup>, <a href = 085 * "https://sic.tech/products/core-crypto-toolkits/eccelerate/" target="_blank"> 086 * https://sic.tech/products/core-crypto-toolkits/eccelerate/</a>) 087 * in your classpath. 088 * <p> 089 * To run this demo the following packages are required: 090 * <ul> 091 * <li> 092 * <code>iaik_cms.jar</code> 093 * </li> 094 * <li> 095 * <code>iaik_jce(_full).jar</code> (<a href="https://sic.tech/products/core-crypto-toolkits/jca-jce/" target="_blank">IAIK-JCE Core Crypto Library</a>). 096 * </li> 097 * <li> 098 * <code>iaik_eccelerate.jar</code> (<a href="https://sic.tech/products/core-crypto-toolkits/eccelerate/" target="_blank">IAIK ECC Library</a>). 099 * </li> 100 * <li> 101 * <code>mail.jar</code> (<a href="http://www.oracle.com/technetwork/java/javamail/index.html" target="_blank">JavaMail API</a>). 102 * </li> 103 * <li> 104 * <code>activation.jar</code> (<a href="http://www.oracle.com/technetwork/java/javase/downloads/index-135046.html" target="_blank">Java Activation Framework</a>; required for JDK versions < 1.6). 105 * </li> 106 * </ul> 107 */ 108 public class SimpleSMimeV4EdDemo extends SimpleSMimeV4EcDemo { 109 110 /** 111 * Default constructor. 112 */ 113 public SimpleSMimeV4EdDemo() { 114 115 System.out.println(); 116 System.out.println("********************************************************************************************"); 117 System.out.println("* SimpleSMimeV4EdDemo demo *"); 118 System.out.println("* (shows how to create and parse (verify, decrypt) signed and encrypted S/MIMEv4 messages) *"); 119 System.out.println("********************************************************************************************"); 120 System.out.println(); 121 122 } 123 124 /** 125 * Gets signing key and certificate. 126 * 127 * @return signing key and certificate 128 */ 129 protected KeyAndCertificate getSignerKeyAndCert() { 130 return new KeyAndCertificate( 131 CMSEccKeyStore.getPrivateKey(CMSEccKeyStore.ECDSA, 132 CMSEccKeyStore.SZ_ED25519), 133 CMSEccKeyStore.getCertificateChain(CMSEccKeyStore.ECDSA, 134 CMSEccKeyStore.SZ_ED25519)); 135 } 136 137 /** 138 * Gets the digest algorithm used for signing. 139 * 140 * @return the digest algorithm 141 */ 142 protected AlgorithmID getDigestAlgorithm() { 143 return AlgorithmID.sha512; 144 } 145 146 /** 147 * Gets the signature algorithm. 148 * 149 * @return the signature algorithm 150 */ 151 protected AlgorithmID getSignatureAlgorithm() { 152 return AlgorithmID.ed25519; 153 } 154 155 /** 156 * Gets the recipient certificates. 157 * 158 * @return the certificates of the recipients 159 */ 160 protected X509Certificate[] getRecipientCerts() { 161 X509Certificate[] recipientCerts = { 162 CMSEccKeyStore.getCertificateChain(CMSEccKeyStore.ECDH, 163 CMSEccKeyStore.SZ_X25519)[0], 164 CMSEccKeyStore.getCertificateChain(CMSEccKeyStore.ECDH, 165 CMSEccKeyStore.SZ_X448)[0], 166 }; 167 return recipientCerts; 168 } 169 170 171 172 /** 173 * The main method. 174 */ 175 public static void main(String[] argv) throws Exception { 176 177 DemoSMimeUtil.initDemos(); 178 // add ECC provider 179 ECCDemoUtil.installIaikEccProvider(); 180 181 (new SimpleSMimeV4EdDemo()).start(); 182 System.out.println("\nReady!"); 183 DemoUtil.waitKey(); 184 } 185 }