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/TripleDESEnvelopedDataDemo.java 4 12.02.25 17:58 Dbratko $ 029// $Revision: 4 $ 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 TripleDES (DES-EDE3) cipher algorithm. 047 * <br> 048 * TripleDES is used for both content encryption (according to RFC 3370) and 049 * content encryption key wrapping (according to RFC 3217). 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 * 067 * <p> 068 * Note that the usage of TripleDES has been deprecated by S/MIMEv4 (RFC 8551), 069 * see {@link AESEnvelopedDataDemo AESEnvelopedDataDemo} for an AES based demo. 070 */ 071public class TripleDESEnvelopedDataDemo extends EnvelopedDataDemo { 072 073 074 /** 075 * Creates an TripleDESEnvelopedDataDemo and setups the demo certificates. 076 * <br> 077 * Keys and certificates are retrieved from the demo KeyStore ("cms.keystore") 078 * file which has to be located in your current working directory and may be 079 * created by running {@link demo.keystore.SetupCMSKeyStore 080 * SetupCMSKeyStore}. 081 * <br> 082 * TripleDES and TripleDES KeyWrap are used for content encryption and 083 * content encryption key wrapping. 084 * 085 * @throws IOException if an file read error occurs 086 * @throws NoSuchAlgorithmException if the requested TripleDES or TripleDES KeyWrap 087 * algorithms are not supported 088 */ 089 public TripleDESEnvelopedDataDemo() throws IOException, NoSuchAlgorithmException { 090 super((AlgorithmID)AlgorithmID.des_EDE3_CBC.clone(), 091 (AlgorithmID)AlgorithmID.cms_3DES_wrap.clone(), 092 192); 093 } 094 095 /** 096 * Main method. 097 * 098 * @throws IOException 099 * if an I/O error occurs when reading required keys 100 * and certificates from files 101 */ 102 public static void main(String argv[]) throws Exception { 103 104 DemoUtil.initDemos(); 105 (new TripleDESEnvelopedDataDemo()).start(); 106 System.out.println("\nReady!"); 107 DemoUtil.waitKey(); 108 } 109}