當前位置: 首頁>>代碼示例>>Java>>正文


Java Cipher.PRIVATE_KEY屬性代碼示例

本文整理匯總了Java中javax.crypto.Cipher.PRIVATE_KEY屬性的典型用法代碼示例。如果您正苦於以下問題:Java Cipher.PRIVATE_KEY屬性的具體用法?Java Cipher.PRIVATE_KEY怎麽用?Java Cipher.PRIVATE_KEY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在javax.crypto.Cipher的用法示例。


在下文中一共展示了Cipher.PRIVATE_KEY屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: constructKey

static final Key constructKey(byte[] encoding, String keyAlgorithm,
                              int keyType)
    throws InvalidKeyException, NoSuchAlgorithmException {
    Key result = null;
    switch (keyType) {
    case Cipher.SECRET_KEY:
        result = ConstructKeys.constructSecretKey(encoding,
                                                  keyAlgorithm);
        break;
    case Cipher.PRIVATE_KEY:
        result = ConstructKeys.constructPrivateKey(encoding,
                                                   keyAlgorithm);
        break;
    case Cipher.PUBLIC_KEY:
        result = ConstructKeys.constructPublicKey(encoding,
                                                  keyAlgorithm);
        break;
    }
    return result;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:20,代碼來源:ConstructKeys.java

示例2: engineUnwrap

/**
 * Unwrap a previously wrapped key.
 *
 * @param wrappedKey the key to be unwrapped.
 *
 * @param wrappedKeyAlgorithm the algorithm the wrapped key is for.
 *
 * @param wrappedKeyType the type of the wrapped key.
 * This is one of <code>Cipher.SECRET_KEY</code>,
 * <code>Cipher.PRIVATE_KEY</code>, or <code>Cipher.PUBLIC_KEY</code>.
 *
 * @return the unwrapped key.
 *
 * @exception InvalidKeyException if <code>wrappedKey</code> does not
 * represent a wrapped key, or if the algorithm associated with the
 * wrapped key is different from <code>wrappedKeyAlgorithm</code>
 * and/or its key type is different from <code>wrappedKeyType</code>.
 *
 * @exception NoSuchAlgorithmException if no installed providers
 * can create keys for the <code>wrappedKeyAlgorithm</code>.
 */
protected final Key engineUnwrap(byte[] wrappedKey,
                                 String wrappedKeyAlgorithm,
                                 int wrappedKeyType)
    throws InvalidKeyException, NoSuchAlgorithmException
{
    byte[] encodedKey;
    Key result = null;

    try {
        encodedKey = engineDoFinal(wrappedKey, 0,
                                   wrappedKey.length);
    } catch (BadPaddingException ePadding) {
        throw new InvalidKeyException();
    } catch (IllegalBlockSizeException eBlockSize) {
        throw new InvalidKeyException();
    }

    switch (wrappedKeyType) {
    case Cipher.SECRET_KEY:
        result = constructSecretKey(encodedKey,
                                    wrappedKeyAlgorithm);
        break;
    case Cipher.PRIVATE_KEY:
        result = constructPrivateKey(encodedKey,
                                     wrappedKeyAlgorithm);
        break;
    case Cipher.PUBLIC_KEY:
        result = constructPublicKey(encodedKey,
                                    wrappedKeyAlgorithm);
        break;
    }

    return result;

}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:56,代碼來源:CipherWithWrappingSpi.java


注:本文中的javax.crypto.Cipher.PRIVATE_KEY屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。