001// Copyright (C) 2002 IAIK 002// https://sic.tech/ 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// This source is provided for inspection purposes and recompilation only, 011// unless specified differently in a contract with IAIK. This source has to 012// be kept in strict confidence and must not be disclosed to any third party 013// under any circumstances. Redistribution in source and binary forms, with 014// or without modification, are <not> permitted in any case! 015// 016// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 017// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 018// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 019// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 020// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 021// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 022// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 023// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 024// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 025// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 026// SUCH DAMAGE. 027// 028// $Header: /IAIK-CMS/current/src/demo/cms/envelopedData/AESEnvelopedDataDemo.java 7 12.02.25 17:58 Dbratko $ 029// $Revision: 7 $ 030// 031 032 033package demo.cms.envelopedData; 034 035import iaik.asn1.structures.AlgorithmID; 036 037import java.io.IOException; 038import java.security.NoSuchAlgorithmException; 039 040import demo.DemoUtil; 041 042 043/** 044 * Demonstrates the usage of class {@link iaik.cms.EnvelopedDataStream} and 045 * {@link iaik.cms.EnvelopedData} for encrypting data using the CMS type 046 * EnvelopedData with the AES cipher algorithm. 047 * <br> 048 * AES is used for both content encryption (according to RFC 3565) and 049 * content encryption key wrapping (according to RFC 3394). 050 * <p> 051 * This demo creates an EnvelopedData object and subsequently shows several 052 * ways that may be used for decrypting the content for some particular 053 * recipient. 054 * <p> 055 * Keys and certificates are retrieved from the demo KeyStore ("cms.keystore") 056 * which has to be located in your current working directory and may be 057 * created by running the {@link demo.keystore.SetupCMSKeyStore 058 * SetupCMSKeyStore} program. 059 * 060 * @see iaik.cms.EnvelopedDataStream 061 * @see iaik.cms.EnvelopedData 062 * @see iaik.cms.RecipientInfo 063 * @see iaik.cms.KeyTransRecipientInfo 064 * @see iaik.cms.KeyAgreeRecipientInfo 065 * @see iaik.cms.KEKRecipientInfo 066 */ 067public class AESEnvelopedDataDemo extends EnvelopedDataDemo { 068 069 070 /** 071 * Creates an AESEnvelopedDataDemo and setups the demo certificates. 072 * <br> 073 * Keys and certificates are retrieved from the demo KeyStore ("cms.keystore") 074 * file which has to be located in your current working directory and may be 075 * created by running {@link demo.keystore.SetupCMSKeyStore 076 * SetupCMSKeyStore}. 077 * <br> 078 * AES and AES KeyWrap are used for content encryption and 079 * content encryption key wrapping. 080 * 081 * @throws IOException if an file read error occurs 082 * @throws NoSuchAlgorithmException if the requested algorithms are not supported 083 */ 084 public AESEnvelopedDataDemo() throws IOException, NoSuchAlgorithmException { 085 super((AlgorithmID)AlgorithmID.aes128_CBC.clone(), 086 (AlgorithmID)AlgorithmID.cms_aes128_wrap.clone(), 087 128); 088 } 089 090 /** 091 * Main method. 092 * 093 * @throws IOException 094 * if an I/O error occurs when reading required keys 095 * and certificates from files 096 */ 097 public static void main(String argv[]) throws Exception { 098 099 DemoUtil.initDemos(); 100 101 // AES with 128 bit keys 102 System.out.println("\n***** AES-128 demo *****\n"); 103 (new AESEnvelopedDataDemo()).start(); 104 // AES with 192 bit keys 105 System.out.println("\n***** AES-192 demo *****\n"); 106 (new EnvelopedDataDemo((AlgorithmID)AlgorithmID.aes192_CBC.clone(), 107 (AlgorithmID)AlgorithmID.cms_aes192_wrap.clone(), 108 192)).start(); 109 // AES with 256 bit keys 110 System.out.println("\n***** AES-256 demo *****\n"); 111 (new EnvelopedDataDemo((AlgorithmID)AlgorithmID.aes256_CBC.clone(), 112 (AlgorithmID)AlgorithmID.cms_aes256_wrap.clone(), 113 256)).start(); 114 115 116 System.out.println("\nReady!"); 117 DemoUtil.waitKey(); 118 } 119}