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/cms/envelopedData/CamelliaEnvelopedDataDemo.java 7 12.02.25 17:58 Dbratko $ 059 // $Revision: 7 $ 060 // 061 062 063 package demo.cms.envelopedData; 064 065 import iaik.asn1.structures.AlgorithmID; 066 067 import java.io.IOException; 068 import java.security.NoSuchAlgorithmException; 069 070 import demo.DemoUtil; 071 072 073 /** 074 * Demonstrates the usage of class {@link iaik.cms.EnvelopedDataStream} and 075 * {@link iaik.cms.EnvelopedData} for encrypting data using the CMS type 076 * EnvelopedData with the Camellia cipher algorithm. 077 * <br> 078 * Camellia is used for both content encryption and content encryption key 079 * wrapping (according to RFC 3657). 080 * <p> 081 * This demo creates an EnvelopedData object and subsequently shows several 082 * ways that may be used for decrypting the content for some particular 083 * recipient. 084 * <p> 085 * Keys and certificates are retrieved from the demo KeyStore ("cms.keystore") 086 * which has to be located in your current working directory and may be 087 * created by running the {@link demo.keystore.SetupCMSKeyStore 088 * SetupCMSKeyStore} program. 089 * <p> 090 * 091 * @see iaik.cms.EnvelopedDataStream 092 * @see iaik.cms.EnvelopedData 093 * @see iaik.cms.RecipientInfo 094 * @see iaik.cms.KeyTransRecipientInfo 095 * @see iaik.cms.KeyAgreeRecipientInfo 096 * @see iaik.cms.KEKRecipientInfo 097 */ 098 public class CamelliaEnvelopedDataDemo extends EnvelopedDataDemo { 099 100 101 /** 102 * Creates an CamelliaEnvelopedDataDemo and setups the demo certificates. 103 * <br> 104 * Keys and certificates are retrieved from the demo KeyStore ("cms.keystore") 105 * file which has to be located in your current working directory and may be 106 * created by running {@link demo.keystore.SetupCMSKeyStore 107 * SetupCMSKeyStore}. 108 * <br> 109 * Camellia and Camellia KeyWrap are used for content encryption and 110 * content encryption key wrapping. 111 * 112 * @throws IOException if an file read error occurs 113 * @throws NoSuchAlgorithmException if the requested algorithms are not supported 114 */ 115 public CamelliaEnvelopedDataDemo() throws IOException, NoSuchAlgorithmException { 116 super((AlgorithmID)AlgorithmID.camellia128_CBC.clone(), 117 (AlgorithmID)AlgorithmID.cms_camellia128_wrap.clone(), 118 128); 119 } 120 121 /** 122 * Main method. 123 * 124 * @throws IOException 125 * if an I/O error occurs when reading required keys 126 * and certificates from files 127 */ 128 public static void main(String argv[]) throws Exception { 129 double iaikProviderVersion = DemoUtil.getIaikProviderVersion(); 130 if (iaikProviderVersion <= 3.18) { 131 System.err.println("This demo requires a IAIK provider version > 3.18! Your IAIK provider version is " + iaikProviderVersion + "."); 132 } else { 133 DemoUtil.initDemos(); 134 // Camellia with 128 bit keys 135 System.out.println("\n***** Camellia-128 demo *****\n"); 136 (new CamelliaEnvelopedDataDemo()).start(); 137 // Camellia with 192 bit keys 138 System.out.println("\n***** Camellia-192 demo *****\n"); 139 (new EnvelopedDataDemo((AlgorithmID)AlgorithmID.camellia192_CBC.clone(), 140 (AlgorithmID)AlgorithmID.cms_camellia192_wrap.clone(), 141 192)).start(); 142 // Camellia with 256 bit keys 143 System.out.println("\n***** Camellia-256 demo *****\n"); 144 (new EnvelopedDataDemo((AlgorithmID)AlgorithmID.camellia256_CBC.clone(), 145 (AlgorithmID)AlgorithmID.cms_camellia256_wrap.clone(), 146 256)).start(); 147 148 System.out.println("\nReady!"); 149 } 150 DemoUtil.waitKey(); 151 } 152 }