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

📄 publickeyinfo.java

📁 有关j2me的很好的例子可以研究一下
💻 JAVA
字号:
/* *  @(#)PublicKeyInfo.java	1.2 01/08/08 *  *  Copyright (c) 2001 Sun Microsystems, Inc., 901 San Antonio Road, *  Palo Alto, CA 94303, U.S.A.  All Rights Reserved. * *  Sun Microsystems, Inc. has intellectual property rights relating *  to the technology embodied in this software.  In particular, and *  without limitation, these intellectual property rights may include *  one or more U.S. patents, foreign patents, or pending *  applications.  Sun, Sun Microsystems, the Sun logo, Java, KJava, *  and all Sun-based and Java-based marks are trademarks or *  registered trademarks of Sun Microsystems, Inc.  in the United *  States and other countries. * *  This software is distributed under licenses restricting its use, *  copying, distribution, and decompilation.  No part of this *  software may be reproduced in any form by any means without prior *  written authorization of Sun and its licensors, if any. * *  FEDERAL ACQUISITIONS:  Commercial Software -- Government Users *  Subject to Standard License Terms and Conditions */package com.sun.midp.publickeystore;import java.io.*;/** The information that needs to be stored for a public key. */public class PublicKeyInfo {    /** used to tag the owner field in a serialized key */    static final byte OWNER_TAG      = 1;    /** used to tag the notBefore field in a serialized key */    static final byte NOT_BEFORE_TAG = 2;    /** used to tag the notAfter field in a serialized key */    static final byte NOT_AFTER_TAG  = 3;    /** used to tag the modulus field in a serialized key */    static final byte MODULUS_TAG    = 4;    /** used to tag the exponent field in a serialized key */    static final byte EXPONENT_TAG   = 5;    /** used to gat the domain field in a serialized key */    static final byte DOMAIN_TAG     = 6;    /** Distinguished Name of the owner */    private String owner;    /** Start of the key's validity period in milliseconds since Jan 1, 1970 */    private long notBefore;    /** End of the key's validity period in milliseconds since Jan 1, 1970 */    private long notAfter;        /** RSA modulus for the public key */    private byte[] modulus;	    /** RSA exponent for the public key */    private byte[] exponent;    /** name of the security domain */    private String domain;    /**     * Deserializes a public key from storage.     * @param storage what to get the key from     * @return a full populated PublicKeyInfo object     * @exception IOException if the key storage was corrupted     */    static PublicKeyInfo getKeyFromStorage(InputStorage storage)             throws IOException {        byte[] tag;        Object value;        String owner;        long notBefore;        long notAfter;        byte[] modulus;        byte[] exponent;        String domain;                tag = new byte[1];        value = storage.readValue(tag);        if (value == null) {            // no more keys            return null;        }        if (tag[0] != OWNER_TAG) {            throw new IOException("public key storage corrupted");        }        owner = (String)value;        value = storage.readValue(tag);        if (tag[0] != NOT_BEFORE_TAG) {            throw new IOException("public key storage corrupted");        }        notBefore = ((Long)value).longValue();        value = storage.readValue(tag);        if (tag[0] != NOT_AFTER_TAG) {            throw new IOException("public key storage corrupted");        }        notAfter = ((Long)value).longValue();        value = storage.readValue(tag);        if (tag[0] != MODULUS_TAG) {            throw new IOException("public key storage corrupted");        }        modulus = (byte[])value;        value = storage.readValue(tag);        if (tag[0] != EXPONENT_TAG) {            throw new IOException("public key storage corrupted");        }        exponent = (byte[])value;        value = storage.readValue(tag);        if (tag[0] != DOMAIN_TAG) {            throw new IOException("public key storage corrupted");        }        domain = (String)value;        return new PublicKeyInfo(owner, notBefore, notAfter,                                 modulus, exponent, domain);    }    /**     * Constructs a PublicKeyInfo object with the specified attributes.     * This constructor is only used by PublicKeyInfo and its subclasses.     * @param owner      distinguished name of the owner     * @param notBefore  start of validity period expressed in milliseconds     *                   since midnight Jan 1, 1970 UTC      * @param notAfter   end of validity period expressed as above     * @param modulus    modulus associated with the RSA Public Key     * @param exponent   exponent associated with the RSA Public Key     * @param domain     security domain of any application authorized     *                   with the corresponding private key, this can be     *                   set to null, allowing it to be set later     */    public PublicKeyInfo(String owner, long notBefore, long notAfter,                   byte[] modulus, byte[] exponent, String domain) {        this.owner = owner;        this.notBefore = notBefore;        this.notAfter = notAfter;        this.modulus = modulus;        this.exponent = exponent;        this.domain = domain;    }    /**     * Gets the distinguished name of the key's owner.     * @return name of key's owner     */    public String getOwner() {        return owner;    }    /**     * Gets the start of the key's validity period in     * milliseconds since Jan 1, 1970.     * @return start of a key's validity period.     */    public long getNotBefore() {        return notBefore;    }    /**     * Gets the end of the key's validity period in     * milliseconds since Jan 1, 1970.     * @return end of a key's validity period.     */    public long getNotAfter() {        return notAfter;    }        /**     * Gets RSA modulus of the public key.     * @return the modulus     */    public byte[] getModulus() {        byte[] retVal = new byte[modulus.length];	System.arraycopy(modulus, 0, retVal, 0, modulus.length);        return retVal;    }	    /**     * Gets RSA exponent of the public key.     * @return the exponent     */    public byte[] getExponent() {        byte[] retVal = new byte[exponent.length];	System.arraycopy(exponent, 0, retVal, 0, exponent.length);        return retVal;    }    /**     * Gets name of the security domain for this key.     * @return the security domain     * @see #setDomain     */    public String getDomain() {        if (domain == null) {            return "untrusted";        }        return domain;    }    /**     * Sets the name of the security domain for this key if it does not have     * a domain.     * @param domain security domain     * @see #getDomain     */    public void setDomain(String domain) {        if (domain != null) {            return;        }        this.domain = domain;    }    /**     * Serializes every field with a tag.     * @param storage what to put the key in     */    void putKeyInStorage(OutputStorage storage)             throws java.io.IOException {        storage.writeValue(OWNER_TAG, owner);        storage.writeValue(NOT_BEFORE_TAG, notBefore);        storage.writeValue(NOT_AFTER_TAG, notAfter);        storage.writeValue(MODULUS_TAG, modulus);        storage.writeValue(EXPONENT_TAG, exponent);        storage.writeValue(DOMAIN_TAG, getDomain());    }}

⌨️ 快捷键说明

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