All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.vt.middleware.crypt.signature.DSASignature Maven / Gradle / Ivy

The newest version!
/**
 * As of "https://github.com/dfish3r/vt-crypt2 "CRYPT" (vt-crypt2) the source
 * code below the package "edu.vt.middleware.crypt" is dual licensed under both
 * the LGPL and Apache 2 license. As REFCODES.ORG source codes are also licensed
 * under the Apache License, v2.0 ("http://www.apache.org/licenses/TEXT-2.0"),
 * the according Apache 2 license principles are to be applied: "... The Apache
 * License is permissive; unlike copyleft licenses, it does not require a
 * derivative work of the software, or modifications to the original, to be
 * distributed using the same license. It still requires application of the same
 * license to all unmodified parts. In every licensed file, original copyright,
 * patent, trademark, and attribution notices must be preserved (excluding
 * notices that do not pertain to any part of the derivative works.) In every
 * licensed file changed, a notification must be added stating that changes have
 * been made to that file..." ("https://en.wikipedia.org/wiki/Apache_License")
 * 
    *
  • "Software can be freely used, modified and distributed in any environment * under this license." *
  • "A copy of the license must be included in the package." (→ see * refcodes-licensing dependency) *
  • "Changes to the source code of the software under the Apache license do * not have to be sent back to the licensor." *
  • "Own software that uses software under the Apache license does not have * to be under the Apache license." *
  • "Your own software may only be called Apache if the Apache Foundation has * given written permission." *
* (freely translated from "https://de.wikipedia.org/wiki/Apache_License") */ /* * $Id: DSASignature.java 2744 2013-06-25 20:20:29Z dfisher $ * * Copyright (C) 2003-2013 Virginia Tech. All rights reserved. * * SEE TEXT FOR MORE INFORMATION * * Author: Middleware Services Email: [email protected] Version: $Revision: 2744 * $ Updated: $Date: 2013-06-25 16:20:29 -0400 (Tue, 25 Jun 2013) $ */ package edu.vt.middleware.crypt.signature; import java.security.PrivateKey; import java.security.PublicKey; import java.security.interfaces.DSAParams; import java.security.interfaces.DSAPrivateKey; import java.security.interfaces.DSAPublicKey; import org.bouncycastle.crypto.params.DSAParameters; import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; import org.bouncycastle.crypto.params.DSAPublicKeyParameters; import org.bouncycastle.crypto.signers.DSASigner; import edu.vt.middleware.crypt.digest.DigestAlgorithm; import edu.vt.middleware.crypt.digest.SHA1; /** * Implements the DSA signature algorithm. * * @author Middleware Services * * @version $Revision: 2744 $ */ public class DSASignature extends AbstractDSASignature { /** Signature algorithm name. */ private static final String ALGORITHM = "DSA"; /** * Creates a new DSA signature class that uses a SHA-1 for aMessage digest * computation. This is the conventional DSA signature configuration. */ public DSASignature() { this( new SHA1() ); } /** * Creates a new DSA signature class that uses the given digest algorithm * for aMessage digest computation. * * @param d Message digest algorithm. */ public DSASignature( final DigestAlgorithm d ) { super( ALGORITHM ); digest = d; signer = new DSASigner(); } /** {@inheritDoc} */ @Override public void setSignKey( final PrivateKey key ) { if ( !DSAPrivateKey.class.isInstance( key ) ) { throw new IllegalArgumentException( "DSA private key required." ); } super.setSignKey( key ); } /** {@inheritDoc} */ @Override public void setVerifyKey( final PublicKey key ) { if ( !DSAPublicKey.class.isInstance( key ) ) { throw new IllegalArgumentException( "DSA public key required." ); } super.setVerifyKey( key ); } /** {@inheritDoc} */ @Override public void initSign() { if ( signKey == null ) { throw new IllegalStateException( "Sign key must be set prior to initialization." ); } final DSAPrivateKey privKey = (DSAPrivateKey) signKey; final DSAParams params = privKey.getParams(); final DSAPrivateKeyParameters bcParams = new DSAPrivateKeyParameters( privKey.getX(), new DSAParameters( params.getP(), params.getQ(), params.getG() ) ); init( true, bcParams ); } /** {@inheritDoc} */ @Override public void initVerify() { if ( verifyKey == null ) { throw new IllegalStateException( "Verify key must be set prior to initialization." ); } final DSAPublicKey pubKey = (DSAPublicKey) verifyKey; final DSAParams params = pubKey.getParams(); final DSAPublicKeyParameters bcParams = new DSAPublicKeyParameters( pubKey.getY(), new DSAParameters( params.getP(), params.getQ(), params.getG() ) ); init( false, bcParams ); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy