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/authenticatedData/HMACwithAESAuthenticatedDataDemo.java 8     12.02.25 17:58 Dbratko $
029// $Revision: 8 $
030
031package demo.cms.authenticatedData;
032
033import iaik.asn1.structures.AlgorithmID;
034import iaik.cms.CMSAlgorithmID;
035
036import java.io.IOException;
037import java.security.NoSuchAlgorithmException;
038
039import demo.DemoUtil;
040
041/**
042 * Demonstrates the usage of class {@link iaik.cms.AuthenticatedDataStream} and
043 * {@link iaik.cms.AuthenticatedData} for recipient-specific protecting the 
044 * integrity of a message using the CMS type AuthenticatedData with the
045 * <code>HMACwithAESwrap</code> algorithm for wrapping the HMAC key.
046 * <p>
047 * 
048 * <b>Attention:</b> This demo uses Static-Static Diffie-Hellman as key management 
049 * technique for providing origin authentication. The mac key is wrapped by
050 * using the HMACwithAESwrap algorithm as specified by RFC 3537.
051 * <p>
052 * This demo requires that you have <code>iaik_esdh.jar</code>
053 * (or <code>iaik_jce_full.jar</code>) in your classpath.
054 * You can download it from <a href="https://sic.tech/products/core-crypto-toolkits/jca-jce/" target="_blank">
055 * https://sic.tech/products/core-crypto-toolkits/jca-jce/</a>.
056 *
057 * @see iaik.cms.AuthenticatedDataStream
058 * @see iaik.cms.AuthenticatedData
059 */
060public class HMACwithAESAuthenticatedDataDemo extends AuthenticatedDataDemo {
061
062  /**
063   * Creates an HMACwithAESAuthenticatedDataDemo and setups the demo certificates.
064   * <br>
065   * Keys and certificates are retrieved from the demo KeyStore ("cms.keystore")
066   * file which has to be located in your current working directory and may be
067   * created by running {@link demo.keystore.SetupCMSKeyStore
068   * SetupCMSKeyStore}.
069   * <br>
070   * HMACwithAESwrap is used as key wrap algorithm.
071   *
072   * @throws IOException if an file read error occurs
073   * @throws NoSuchAlgorithmException if no implementation for the requested key wrap algorithm is available
074   */
075  public HMACwithAESAuthenticatedDataDemo() throws IOException, NoSuchAlgorithmException {
076    super((AlgorithmID)CMSAlgorithmID.cms_HMACwithAES_wrap.clone(),
077          128);
078  }
079      
080  /**
081   * Main method.
082   *
083   * @throws IOException
084   *            if an I/O error occurs when reading required keys
085   *            and certificates from files
086   */
087  public static void main(String argv[]) throws Exception {
088
089    DemoUtil.initDemos();
090    (new HMACwithAESAuthenticatedDataDemo()).start();
091    System.out.println("\nReady!");
092    DemoUtil.waitKey();
093  }
094}
095
096