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


        } else if (SecurityTokenConstants.KeyIdentifier_NoKeyInfo.equals(keyIdentifier)) {
            DefaultTokenSecurityEvent tokenEvent =
                (DefaultTokenSecurityEvent)securityEventListener.getSecurityEvent(SecurityEventConstants.DefaultToken);
            assertNotNull(tokenEvent);
            Key processedKey = tokenEvent.getSecurityToken().getSecretKey().values().iterator().next();
            assertEquals(processedKey, key);
        } else if (SecurityTokenConstants.KeyIdentifier_KeyName.equals(keyIdentifier)) {
            KeyNameTokenSecurityEvent tokenEvent =
                (KeyNameTokenSecurityEvent)securityEventListener.getSecurityEvent(SecurityEventConstants.KeyNameToken);
            assertNotNull(tokenEvent);
            Key processedKey = tokenEvent.getSecurityToken().getSecretKey().values().iterator().next();
            assertEquals(processedKey, key);
            assertNotNull(((KeyNameSecurityToken)tokenEvent.getSecurityToken()).getKeyName());
        } else {
            X509TokenSecurityEvent tokenEvent =
                (X509TokenSecurityEvent)securityEventListener.getSecurityEvent(SecurityEventConstants.X509Token);
            assertNotNull(tokenEvent);
            X509SecurityToken x509SecurityToken =
                (X509SecurityToken)tokenEvent.getSecurityToken();
            assertNotNull(x509SecurityToken);
            if (SecurityTokenConstants.KeyIdentifier_X509SubjectName.equals(keyIdentifier)) {
                Key processedKey = x509SecurityToken.getPublicKey();
                assertEquals(processedKey, key);
                assertNotNull(((X509SubjectNameSecurityToken)x509SecurityToken).getSubjectName());
            } else if (SecurityTokenConstants.KeyIdentifier_IssuerSerial.equals(keyIdentifier)) {
                Key processedKey = x509SecurityToken.getPublicKey();
                assertEquals(processedKey, key);
                assertNotNull(((X509IssuerSerialSecurityToken)x509SecurityToken).getIssuerName());
                assertNotNull(((X509IssuerSerialSecurityToken)x509SecurityToken).getSerialNumber());
            }
        }
View Full Code Here


     * @param alias       The alias of the certificate in the specified keyStore
     * @param keyPassword Password to access private key
     * @return PrivateKey if there is a one , otherwise null
     */
    public PrivateKey getPrivateKey(String alias, String keyPassword) {
        Key key = super.getKey(alias, keyPassword);
        if (key instanceof PrivateKey) {
            return (PrivateKey) key;
        }
        return null;
    }
View Full Code Here

     * Returns the private key based on initialization data
     *
     * @return PrivateKey if there is a one , otherwise null
     */
    public PrivateKey getPrivateKey() {
        Key key = super.getDefaultPrivateKey();
        if (key instanceof PrivateKey) {
            return (PrivateKey) key;
        }
        return null;
    }
View Full Code Here

     * Returns the private key based on initialization data
     *
     * @return PrivateKey if there is a one , otherwise null
     */
    public PrivateKey getPrivateKey(String alias) {
        Key key = super.getPrivateKey(alias);
        if (key instanceof PrivateKey) {
            return (PrivateKey) key;
        }
        return null;
    }
View Full Code Here

            // Source  as an in-lined
            String source = getArgument(cmd, SOURCE_IN_LINED, null);
            assertEmpty(source, SOURCE_IN_LINED);

            Key key = findKey(cmd, cipherInformation);

            boolean isEncrypt = (cipherInformation.getCipherOperationMode() ==
                    CipherOperationMode.ENCRYPT);

            EncryptionProvider encryptionProvider = null;
View Full Code Here

     */
    private static Key findKey(CommandLine cmd, CipherInformation cipherInformation) {
        // if pass phrase is specified, use simple symmetric en-/decryption
        String passPhrase = getArgument(cmd, PASSPHRASE, null);

        Key key = null;

        if (passPhrase != null) {
            key = new SecretKeySpec(passPhrase.getBytes(), cipherInformation.getAlgorithm());

        } else {
View Full Code Here

                );
        } else {
            c = contextCipher;
        }

        Key ret;
       
        try {
            EncryptionMethod encMethod = encryptedKey.getEncryptionMethod();
            OAEPParameterSpec oaepParameters =
                constructOAEPParameters(
View Full Code Here

        }

        if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
            String keyName = element.getFirstChild().getNodeValue();
            try {
                Key key = keyStore.getKey(keyName, password);
                if (key instanceof SecretKey) {
                    return (SecretKey) key;
                }
            } catch (Exception e) {
                log.debug("Cannot recover the key", e);
View Full Code Here

        KeyStore keyStore = KeyStore.getInstance("jks");
        keyStore.load(
                this.getClass().getClassLoader().getResource("transmitter.jks").openStream(),
                "default".toCharArray()
        );
        Key key = keyStore.getKey("transmitter", "default".toCharArray());
        properties.setSignatureKey(key);
        X509Certificate cert = (X509Certificate) keyStore.getCertificate("transmitter");
        properties.setSignatureCerts(new X509Certificate[]{cert});

        // Set the key up
View Full Code Here

        KeyStore keyStore = KeyStore.getInstance("jks");
        keyStore.load(
                this.getClass().getClassLoader().getResource("transmitter.jks").openStream(),
                "default".toCharArray()
        );
        Key key = keyStore.getKey("transmitter", "default".toCharArray());
        properties.setSignatureKey(key);
        X509Certificate cert = (X509Certificate) keyStore.getCertificate("transmitter");
        properties.setSignatureCerts(new X509Certificate[]{cert});

        // Set the key up
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.