当前位置: 首页>>代码示例>>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;未经允许,请勿转载。