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


Java KeyException類代碼示例

本文整理匯總了Java中java.security.KeyException的典型用法代碼示例。如果您正苦於以下問題:Java KeyException類的具體用法?Java KeyException怎麽用?Java KeyException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: decrypt

import java.security.KeyException; //導入依賴的package包/類
/**
 * Decrypt a property if the data definition (model-specific) requires it.
 * 
 * @param propertyQName             the property qualified name
 * @param inbound                   the property to decrypt
 * @return                          the decrypted property or the original if it wasn't encrypted
 */
public Serializable decrypt(QName propertyQName, Serializable inbound)
{
    PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName);
    if (inbound == null || propertyDef == null || !(propertyDef.getDataType().getName().equals(DataTypeDefinition.ENCRYPTED)))
    {
        return inbound;
    }
    if (!(inbound instanceof SealedObject))
    {
        return inbound;
    }
    try
    {
     Serializable outbound = encryptor.unsealObject(KeyProvider.ALIAS_METADATA, inbound);
     // Done
     return outbound;
    }
    catch(KeyException e)
    {
    	throw new AlfrescoRuntimeException("Invalid metadata decryption key", e);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:30,代碼來源:MetadataEncryptor.java

示例2: select_publicKey_exception

import java.security.KeyException; //導入依賴的package包/類
@Test()
public void select_publicKey_exception() throws Exception {
    // given
    KeyInfo keyinfo = mock(KeyInfo.class);
    ArrayList<XMLStructure> list = new ArrayList<XMLStructure>();
    KeyValue struct = mock(KeyValue.class);
    list.add(struct);
    doReturn(list).when(keyinfo).getContent();
    doThrow(new KeyException("test")).when(struct).getPublicKey();

    // when
    try {
        selector.select(keyinfo, null, null, null);
        fail();
    } catch (KeySelectorException e) {
        assertTrue(e.getCause().getMessage().contains("test"));
    }
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:19,代碼來源:KeyValueKeySelectorTest.java

示例3: generateSymmetricKey

import java.security.KeyException; //導入依賴的package包/類
/**
 * Generates a random Java JCE symmetric Key object from the specified XML Encryption algorithm URI.
 * 
 * @param algoURI The XML Encryption algorithm URI
 * @return a randomly-generated symmetric Key
 * @throws NoSuchAlgorithmException thrown if the specified algorithm is invalid
 * @throws KeyException thrown if the length of the key to generate could not be determined
 */
public static SecretKey generateSymmetricKey(String algoURI) throws NoSuchAlgorithmException, KeyException {
    Logger log = getLogger();
    String jceAlgorithmName = getKeyAlgorithmFromURI(algoURI);
    if (DatatypeHelper.isEmpty(jceAlgorithmName)) {
        log.error("Mapping from algorithm URI '" + algoURI
                + "' to key algorithm not available, key generation failed");
        throw new NoSuchAlgorithmException("Algorithm URI'" + algoURI + "' is invalid for key generation");
    }
    Integer keyLength = getKeyLengthFromURI(algoURI);
    if (keyLength == null) {
        log.error("Key length could not be determined from algorithm URI, can't generate key");
        throw new KeyException("Key length not determinable from algorithm URI, could not generate new key");
    }
    KeyGenerator keyGenerator = KeyGenerator.getInstance(jceAlgorithmName);
    keyGenerator.init(keyLength);
    return keyGenerator.generateKey();
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:SecurityHelper.java

示例4: decodePrivateKey

import java.security.KeyException; //導入依賴的package包/類
/**
 * Decodes RSA/DSA private keys in DER, PEM, or PKCS#8 (encrypted or unencrypted) formats.
 * 
 * @param key encoded key
 * @param password decryption password or null if the key is not encrypted
 * 
 * @return deocded private key
 * 
 * @throws KeyException thrown if the key can not be decoded
 */
public static PrivateKey decodePrivateKey(File key, char[] password) throws KeyException {
    if (!key.exists()) {
        throw new KeyException("Key file " + key.getAbsolutePath() + " does not exist");
    }

    if (!key.canRead()) {
        throw new KeyException("Key file " + key.getAbsolutePath() + " is not readable");
    }

    try {
        return decodePrivateKey(DatatypeHelper.fileToByteArray(key), password);
    } catch (IOException e) {
        throw new KeyException("Error reading Key file " + key.getAbsolutePath(), e);
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:SecurityHelper.java

示例5: newKeyValue

import java.security.KeyException; //導入依賴的package包/類
public KeyValue newKeyValue(PublicKey key)  throws KeyException {
    String algorithm = key.getAlgorithm();
    if (algorithm.equals("DSA")) {
        return new DOMKeyValue.DSA(key);
    } else if (algorithm.equals("RSA")) {
        return new DOMKeyValue.RSA(key);
    } else if (algorithm.equals("EC")) {
        return new DOMKeyValue.EC(key);
    } else {
        throw new KeyException("unsupported key algorithm: " + algorithm);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:13,代碼來源:DOMKeyInfoFactory.java

示例6: equals

import java.security.KeyException; //導入依賴的package包/類
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof KeyValue)) {
        return false;
    }
    try {
        KeyValue kv = (KeyValue)obj;
        if (publicKey == null ) {
            if (kv.getPublicKey() != null) {
                return false;
            }
        } else if (!publicKey.equals(kv.getPublicKey())) {
            return false;
        }
    } catch (KeyException ke) {
        // no practical way to determine if the keys are equal
        return false;
    }

    return true;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:DOMKeyValue.java

示例7: select

import java.security.KeyException; //導入依賴的package包/類
public KeySelectorResult select(KeyInfo keyInfo,
                                KeySelector.Purpose purpose,
                                AlgorithmMethod method,
                                XMLCryptoContext context)
    throws KeySelectorException {
    if (keyInfo == null) {
        throw new KeySelectorException("Null KeyInfo object!");
    }
    SignatureMethod sm = (SignatureMethod) method;

    for (XMLStructure xmlStructure : keyInfo.getContent()) {
        if (xmlStructure instanceof KeyValue) {
            PublicKey pk = null;
            try {
                pk = ((KeyValue)xmlStructure).getPublicKey();
            } catch (KeyException ke) {
                throw new KeySelectorException(ke);
            }
            // make sure algorithm is compatible with method
            if (algEquals(sm.getAlgorithm(), pk.getAlgorithm())) {
                return new SimpleKSResult(pk);
            }
        }
    }
    throw new KeySelectorException("No KeyValue element found!");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:27,代碼來源:KeySelectors.java

示例8: testWALKeyWrappingWithIncorrectKey

import java.security.KeyException; //導入依賴的package包/類
@Test(expected = KeyException.class)
public void testWALKeyWrappingWithIncorrectKey() throws Exception {
  // set up the key provider for testing to resolve a key for our test subject
  Configuration conf = new Configuration(); // we don't need HBaseConfiguration for this
  conf.set(HConstants.CRYPTO_KEYPROVIDER_CONF_KEY, KeyProviderForTesting.class.getName());

  // generate a test key
  byte[] keyBytes = new byte[AES.KEY_LENGTH];
  new SecureRandom().nextBytes(keyBytes);
  String algorithm = conf.get(HConstants.CRYPTO_WAL_ALGORITHM_CONF_KEY, HConstants.CIPHER_AES);
  Key key = new SecretKeySpec(keyBytes, algorithm);

  // wrap the test key
  byte[] wrappedKeyBytes = EncryptionUtil.wrapKey(conf, "hbase", key);
  assertNotNull(wrappedKeyBytes);

  // unwrap with an incorrect key
  EncryptionUtil.unwrapWALKey(conf, "other", wrappedKeyBytes);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:20,代碼來源:TestEncryptionUtil.java

示例9: getPublicExponent

import java.security.KeyException; //導入依賴的package包/類
/**
 * Returns the public exponent.
 */
public BigInteger getPublicExponent() {

    if (exponent == null) {

        try {
            publicKeyBlob = getPublicKeyBlob(hCryptKey);
            exponent = new BigInteger(1, getExponent(publicKeyBlob));

        } catch (KeyException e) {
            throw new ProviderException(e);
        }
    }

    return exponent;
}
 
開發者ID:campolake,項目名稱:openjdk9,代碼行數:19,代碼來源:RSAPublicKey.java

示例10: getModulus

import java.security.KeyException; //導入依賴的package包/類
/**
 * Returns the modulus.
 */
public BigInteger getModulus() {

    if (modulus == null) {

        try {
            publicKeyBlob = getPublicKeyBlob(hCryptKey);
            modulus = new BigInteger(1, getModulus(publicKeyBlob));

        } catch (KeyException e) {
            throw new ProviderException(e);
        }
    }

    return modulus;
}
 
開發者ID:campolake,項目名稱:openjdk9,代碼行數:19,代碼來源:RSAPublicKey.java

示例11: getPublicExponent

import java.security.KeyException; //導入依賴的package包/類
/**
 * Returns the public exponent.
 */
public BigInteger getPublicExponent() {

    if (exponent == null) {

        try {
            publicKeyBlob = getPublicKeyBlob(handles.hCryptKey);
            exponent = new BigInteger(1, getExponent(publicKeyBlob));

        } catch (KeyException e) {
            throw new ProviderException(e);
        }
    }

    return exponent;
}
 
開發者ID:JetBrains,項目名稱:jdk8u_jdk,代碼行數:19,代碼來源:RSAPublicKey.java

示例12: getModulus

import java.security.KeyException; //導入依賴的package包/類
/**
 * Returns the modulus.
 */
public BigInteger getModulus() {

    if (modulus == null) {

        try {
            publicKeyBlob = getPublicKeyBlob(handles.hCryptKey);
            modulus = new BigInteger(1, getModulus(publicKeyBlob));

        } catch (KeyException e) {
            throw new ProviderException(e);
        }
    }

    return modulus;
}
 
開發者ID:JetBrains,項目名稱:jdk8u_jdk,代碼行數:19,代碼來源:RSAPublicKey.java

示例13: decrypt

import java.security.KeyException; //導入依賴的package包/類
public byte[] decrypt(byte[] encryptedInput) throws CryptoException {
    try {
        SecretKey key = new SecretKeySpec(getAESKey(), ALGORITHM_AES);
        Cipher cipher = Cipher.getInstance(AES_TRANSFORMATION);
        String encodedIV = storage.retrieveString(KEY_IV_ALIAS);
        if (TextUtils.isEmpty(encodedIV)) {
            throw new InvalidAlgorithmParameterException("The AES Key exists but an IV was never stored. Try to encrypt something first.");
        }
        byte[] iv = Base64.decode(encodedIV, Base64.DEFAULT);
        cipher.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv));
        return cipher.doFinal(encryptedInput);
    } catch (KeyException | NoSuchAlgorithmException | NoSuchPaddingException | InvalidAlgorithmParameterException | BadPaddingException | IllegalBlockSizeException e) {
        Log.e(TAG, "Error while decrypting the input.", e);
        throw new CryptoException("Error while decrypting the input.", e);
    }
}
 
開發者ID:auth0,項目名稱:Auth0.Android,代碼行數:17,代碼來源:CryptoUtil.java

示例14: shouldThrowOnNoSuchProviderErrorWhenTryingToObtainRSAKeys

import java.security.KeyException; //導入依賴的package包/類
@Test
public void shouldThrowOnNoSuchProviderErrorWhenTryingToObtainRSAKeys() throws Exception {
    ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", 19);
    exception.expect(KeyException.class);
    exception.expectMessage("An error occurred while trying to obtain the RSA KeyPair Entry from the Android KeyStore.");

    PowerMockito.when(keyStore.containsAlias(KEY_ALIAS)).thenReturn(false);
    KeyPairGeneratorSpec spec = PowerMockito.mock(KeyPairGeneratorSpec.class);
    KeyPairGeneratorSpec.Builder builder = newKeyPairGeneratorSpecBuilder(spec);
    PowerMockito.whenNew(KeyPairGeneratorSpec.Builder.class).withAnyArguments().thenReturn(builder);

    PowerMockito.mockStatic(KeyPairGenerator.class);
    PowerMockito.when(KeyPairGenerator.getInstance(ALGORITHM_RSA, ANDROID_KEY_STORE))
            .thenThrow(new NoSuchProviderException());

    cryptoUtil.getRSAKeyEntry();
}
 
開發者ID:auth0,項目名稱:Auth0.Android,代碼行數:18,代碼來源:CryptoUtilTest.java

示例15: shouldThrowOnNoSuchAlgorithmErrorWhenTryingToObtainRSAKeys

import java.security.KeyException; //導入依賴的package包/類
@Test
public void shouldThrowOnNoSuchAlgorithmErrorWhenTryingToObtainRSAKeys() throws Exception {
    ReflectionHelpers.setStaticField(Build.VERSION.class, "SDK_INT", 19);
    exception.expect(KeyException.class);
    exception.expectMessage("An error occurred while trying to obtain the RSA KeyPair Entry from the Android KeyStore.");

    PowerMockito.when(keyStore.containsAlias(KEY_ALIAS)).thenReturn(false);
    KeyPairGeneratorSpec spec = PowerMockito.mock(KeyPairGeneratorSpec.class);
    KeyPairGeneratorSpec.Builder builder = newKeyPairGeneratorSpecBuilder(spec);
    PowerMockito.whenNew(KeyPairGeneratorSpec.Builder.class).withAnyArguments().thenReturn(builder);

    PowerMockito.mockStatic(KeyPairGenerator.class);
    PowerMockito.when(KeyPairGenerator.getInstance(ALGORITHM_RSA, ANDROID_KEY_STORE))
            .thenThrow(new NoSuchAlgorithmException());

    cryptoUtil.getRSAKeyEntry();
}
 
開發者ID:auth0,項目名稱:Auth0.Android,代碼行數:18,代碼來源:CryptoUtilTest.java


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