⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 secretkeycertificatepacket.java

📁 面向应用的智能安全代理平台和工具包是一个综合网络应用的安全共性需求而设计和实现的一个通用性的网络信息安全应用支撑平台
💻 JAVA
字号:
package au.net.aba.pgp;

/*
 * $Id: SecretKeyCertificatePacket.java,v 1.6 1998/10/19 06:32:41 leachbj Exp $
 * $Author: leachbj $
 *
 * Copyright (C) 1996-1998 Australian Business Access Pty Ltd.
 * All rights reserved.
 * 
 * Use, modification, copying and distribution of this software is subject the
 * terms and conditions of the ABA Public Licence. See the file
 * "PUBLIC_LICENCE" for additional information.
 *
 * If you have not received a copy of the Public Licence, you must destroy all
 * copies of this file immediately. 
 *
 * $Source: /aba/CVSROOT/jdk1.1/src/au.net.aba/pgp/SecretKeyCertificatePacket.java,v $
 * $Revision: 1.6 $
 * $Date: 1998/10/19 06:32:41 $
 * $State: Exp $
 */

import java.io.*;
import java.math.*;
import java.security.*;

import javax.crypto.spec.*;

import java.security.*;
import java.security.spec.*;

//
// Secret key certificate packet.
//

class SecretKeyCertificatePacket extends Packet
{
	public final static String ident = "$Id: SecretKeyCertificatePacket.java,v 1.6 1998/10/19 06:32:41 leachbj Exp $";

	public byte version;			// PGP version
	public long timestamp;			// creation timestamp
	public int validity;			// validity period
	public byte pkAlgorithm;		// public key scheme algorithm
	public Multiprecision modulus;		// public key modulus
	public Multiprecision exponent;		// public key exponent
	public byte cipherAlgorithm;		// secret component cipher
	public byte[] cipherFeedback;		// cipher feedback
	public Multiprecision exponent_d;	// decryption exponent
	public Multiprecision factor_p;		// secret factor p
	public Multiprecision factor_q;		// secret factor q
	public Multiprecision inverse;		// secret multiplicative inverse


	//
	// Construct from an input stream.
	// 
	public SecretKeyCertificatePacket (InputStream input)
		throws IOException
	{
		// build packet input stream
		DataInputStream data = buildCipherPacketInputStream (
			input,(byte)0x05,
			"secret key certificate packet expected");

		// general information
		version = data.readByte ();
		timestamp = data.readUnsignedShort () << 16;
		timestamp |= data.readUnsignedShort ();
		validity = data.readUnsignedShort ();

		// public key details
		pkAlgorithm = data.readByte ();
		modulus = new Multiprecision (data);
		exponent = new Multiprecision (data);

		// private key protection cipher
		cipherAlgorithm = data.readByte ();
		if (cipherAlgorithm != 0){
			cipherFeedback = new byte[8];
			data.readFully (cipherFeedback);
		}

		// private key
		exponent_d = new Multiprecision (data);
		factor_p = new Multiprecision (data);
		factor_q = new Multiprecision (data);
		inverse = new Multiprecision (data);

		// read CRC
		int crc = data.readUnsignedShort ();
	}
	/**
	 * return the private key associated with this certificate.
	 *
	 * @param provider	algorithm provider for the key factory we use.
	 */
	public PrivateKey getKey(
		String provider)
		throws KeyException
	{
		RSAPrivateCrtKeySpec	spec;
		BigInteger		p, q;
		BigInteger		pMinus1, qMinus1;

		p = factor_p.toBigInteger();
		q = factor_q.toBigInteger();

		if (p.compareTo(q) < 0)
		{
			BigInteger	tmp = p;
			p = q;
			q = tmp;
		}

		pMinus1 = p.subtract(BigInteger.valueOf(1));
		qMinus1 = q.subtract(BigInteger.valueOf(1));

		spec = new RSAPrivateCrtKeySpec(
				modulus.toBigInteger(),
				exponent.toBigInteger(),
				exponent_d.toBigInteger(),
				p,
				q,
				exponent_d.toBigInteger().remainder(pMinus1),
				exponent_d.toBigInteger().remainder(qMinus1),
				q.modInverse(p));

		try
		{
			KeyFactory	keyFact;

			keyFact = KeyFactory.getInstance("RSA", provider);

			return keyFact.generatePrivate(spec);
		}
		catch (Exception e)
		{
			throw new KeyException(e.toString());
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -