Package java.security

Examples of java.security.Key

Keys are generally obtained through key generators, certificates, or various Identity classes used to manage keys. Keys may also be obtained from key specifications (transparent representations of the underlying key material) through the use of a key factory (see {@link KeyFactory}).

A Key should use KeyRep as its serialized representation. Note that a serialized Key may contain sensitive information which should not be exposed in untrusted environments. See the Security Appendix of the Serialization Specification for more information. @see PublicKey @see PrivateKey @see KeyPair @see KeyPairGenerator @see KeyFactory @see KeyRep @see java.security.spec.KeySpec @see Identity @see Signer @version 1.57 06/04/21 @author Benjamin Renaud


    @Override
    protected Key getKey(String algorithmURI, XMLSecurityConstants.AlgorithmUsage algorithmUsage,
                         String correlationID) throws XMLSecurityException {

        Key key = getSecretKey().get(algorithmURI);
        if (key != null) {
            return key;
        }

        if (this.kerberosTokenDecoder == null) {
View Full Code Here


                );
                algorithmSuiteValidator.checkSignatureDerivedKeyLength(
                    ((WSDerivedKeyTokenPrincipal)principal).getLength()
                );
            } else {
                Key key = null;
                if (certs != null && certs[0] != null) {
                    key = certs[0].getPublicKey();
                } else if (publicKey != null) {
                    key = publicKey;
                }
View Full Code Here

       
        //
        // Perform the signature verification and build up a List of elements that the
        // signature refers to
        //
        Key key = null;
        if (certs != null && certs[0] != null) {
            key = certs[0].getPublicKey();
        } else if (publicKey != null) {
            key = publicKey;
        } else {
View Full Code Here

  @Test(timeout=30000)
  public void testKeyStoreKeyProviderWithPassword() throws Exception {
    KeyProvider provider = new KeyStoreKeyProvider();
    provider.init("jceks://" + storeFile.getAbsolutePath() + "?password=" + PASSWORD);
    Key key = provider.getKey(ALIAS);
    assertNotNull(key);
    byte[] keyBytes = key.getEncoded();
    assertEquals(keyBytes.length, KEY.length);
    for (int i = 0; i < KEY.length; i++) {
      assertEquals(keyBytes[i], KEY[i]);
    }
  }
View Full Code Here

  @Test(timeout=30000)
  public void testKeyStoreKeyProviderWithPasswordFile() throws Exception {
    KeyProvider provider = new KeyStoreKeyProvider();
    provider.init("jceks://" + storeFile.getAbsolutePath() + "?passwordFile=" +
      URLEncoder.encode(passwordFile.getAbsolutePath(), "UTF-8"));
    Key key = provider.getKey(ALIAS);
    assertNotNull(key);
    byte[] keyBytes = key.getEncoded();
    assertEquals(keyBytes.length, KEY.length);
    for (int i = 0; i < KEY.length; i++) {
      assertEquals(keyBytes[i], KEY[i]);
    }
  }
View Full Code Here

          if(getKeyProvider() == null) {
            throw new IllegalStateException("Data file is encrypted but no " +
                " provider was specified");
          }
          ProtosFactory.LogFileEncryption encryption = metaData.getEncryption();
          Key key = getKeyProvider().getKey(encryption.getKeyAlias());
          decryptor = CipherProviderFactory.
              getDecrypter(encryption.getCipherProvider(), key,
                  encryption.getParameters().toByteArray());
        }
        setLogFileID(metaData.getLogFileID());
View Full Code Here

        if (null == trustStore) {
            throw new IllegalStateException("A trust store must be defined for asymmetric key encryption.");
        }
       
        Key keyEncryptionKey = getPublicKey(this.trustStore, exchangeRecipientAlias, this.trustStorePassword);
       
        if (null == keyEncryptionKey) {
            throw new IllegalStateException("No key for the alias [ " + exchangeRecipientAlias
                + " ] exists in " + "the configured trust store.");
        }
       
        Key dataEncryptionKey = generateDataEncryptionKey();
       
        XMLCipher keyCipher;
        if (null != this.getKeyCipherAlgorithm()) {
            keyCipher = XMLCipher.getInstance(this.getKeyCipherAlgorithm(), null, digestAlgorithm);
        } else {
View Full Code Here

        keyCipher.init(XMLCipher.WRAP_MODE, keyEncryptionKey);
        encrypt(exchange, document, stream, dataEncryptionKey, keyCipher);
    }
    
    private void encryptSymmetric(Exchange exchange, Document document, OutputStream stream) throws Exception {
        Key keyEncryptionKey;
        Key dataEncryptionKey;
        if (xmlCipherAlgorithm.equals(XMLCipher.TRIPLEDES)) {
            keyEncryptionKey = generateKeyEncryptionKey("DESede");
            dataEncryptionKey = generateDataEncryptionKey();
        } else if (xmlCipherAlgorithm.equals(XMLCipher.SEED_128)) {
            keyEncryptionKey = generateKeyEncryptionKey("SEED");
View Full Code Here

    /**
     * Returns the private key for the specified alias, or null if the alias or private key is not found.
     */
    // TODO Move this to a crypto utility class
    private Key getPrivateKey(KeyStore keystore, String alias, String password) throws Exception {
        Key key = keystore.getKey(alias, password.toCharArray());
        if (key instanceof PrivateKey) {
            return key;
        } else {
            return null;
        }
View Full Code Here

    /**
     * Returns the public key for the specified alias, or null if the alias or private key is not found.
     */   
    // TODO Move this to a crypto utility class
    private Key getPublicKey(KeyStore keystore, String alias, String password) throws Exception {
        Key key = keystore.getKey(alias, password.toCharArray());
        if (key instanceof PublicKey) {
            return key;
        } else {
            java.security.cert.Certificate cert = keystore.getCertificate(alias);
            // Get public key
View Full Code Here

TOP

Related Classes of java.security.Key

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.