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

📄 publickeystore.java

📁 有关j2me的很好的例子可以研究一下
💻 JAVA
字号:
/* *  @(#)PublicKeyStore.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.*;import java.util.*;/** * A read-only public keystore for use with KSSL. */public class PublicKeyStore {    /** Holds the all the keys as {@link PublicKeyInfo} objects. */    private Vector keyList = null;    /**     * Constructor for subclasses.     */    protected PublicKeyStore() {    };    /**     * Constructs a read-only keystore from a serialized keystore created     * by {@link PublicKeyStoreBuilder}.     * @param in stream to read a keystore serialized by     *        {@link PublicKeyStoreBuilder#serialize(OutputStream)} from     * @exception IOException if the key storage was corrupted     */    public PublicKeyStore(InputStream in) throws IOException {        initPublicKeyStore(in, new Vector());    }    /**     * Lets this class work with a writeable key list of a subclass.     * This is needed because we cannot make the key list in this     * class protected for security reasons. This method will only     * work if the PublicKeyStore has not been initialized.     * @param sharedKeyList key list of a subclass     */    protected void initPublicKeyStore(Vector sharedKeyList) {        if (keyList != null) {            return;        }        keyList = sharedKeyList;    }    /**     * Lets this class work with a writeable key list of a subclass and     * initialized that key list from a serialized key list.     * This is needed because we cannot make the key list in this     * class protected for security reasons. This method will only     * work if the PublicKeyStore has not been initialized.      * @param sharedKeyList key list of a subclass     * @param in stream to read the serialized keystore     * @exception IOException if the key storage was corrupted     */    protected void initPublicKeyStore(InputStream in, Vector sharedKeyList)            throws IOException {        InputStorage storage = new InputStorage(in);        PublicKeyInfo keyInfo;        if (keyList != null) {            return;        }        keyList = sharedKeyList;        for (;;) {            keyInfo = PublicKeyInfo.getKeyFromStorage(storage);            if (keyInfo == null)                return;                        keyList.addElement(keyInfo);        }    }    /**     * Finds a key based on the owners distinguished name.     * @param alias distinguished name of key's owner     * @return public key information     */    public synchronized PublicKeyInfo findKey(String alias) {        Enumeration e;        PublicKeyInfo keyInfo;          e = keyList.elements();        while (e.hasMoreElements()) {            keyInfo = (PublicKeyInfo)e.nextElement();	    if (keyInfo.getOwner().compareTo(alias) == 0) {                return keyInfo;            }	}        return null;    }    /**     * Get an enumeration of owner names from the keystore.     * @return enumeration of owner names     */    public Enumeration getOwners() {	return new OwnerEnum(keyList);    }    /**     * Gets the number of keys in the store.     * @return number of keys in the keystore     */    synchronized int numberOfKeys() {        return keyList.size();    }}/** Implements an Enumeration of key owner names. */class OwnerEnum implements Enumeration {    /** enumeration of public keys */    private Enumeration enum;    /**     * Constructs a OwnerEnum from a vector public keys.     * @param keyList vector of {@link PublicKeyInfo} objects     */    OwnerEnum(Vector keyList) { 	enum = keyList.elements();    }    /**      * Check for more items in the enumeration.     * @return true, if more items to be processed     */         public boolean hasMoreElements() {        return enum.hasMoreElements();    }    /**     * Get the next element in the enumeration.     * @return next object      */    public Object nextElement() {        // only give out the name of the owner        return ((PublicKeyInfo)enum.nextElement()).getOwner();    }}

⌨️ 快捷键说明

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