Example usage for java.security Provider getInfo

List of usage examples for java.security Provider getInfo

Introduction

In this page you can find the example usage for java.security Provider getInfo.

Prototype

public String getInfo() 

Source Link

Document

Returns a human-readable description of the provider and its services.

Usage

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Provider p = Security.getProvider("Rot13Provider");
    System.out.println("Provider name: " + p.getName());
    System.out.println("Provider version: " + p.getVersion());
    System.out.println("Provider information: " + p.getInfo());

    Cipher cipher = Cipher.getInstance("ROT13", "Rot13Provider");
    System.out.println("Cipher: " + cipher.getAlgorithm());
    String testString = "This is a test!";
    cipher.init(Cipher.ENCRYPT_MODE, (Key) null, new SecureRandom());
    byte[] b1 = cipher.doFinal(testString.getBytes());
    cipher.init(Cipher.DECRYPT_MODE, (Key) null, new SecureRandom());
    byte[] b2 = cipher.doFinal(b1);
    System.out.println("Decrypted data as a String: " + new String(b2));
}

From source file:net.sf.jsignpdf.Signer.java

/**
 * Writes info about security providers to the {@link Logger} instance. The
 * log-level for messages is TRACE./*from  w w  w.ja  v a2 s.  c om*/
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private static void traceInfo() {
    if (LOGGER.isTraceEnabled()) {
        try {
            Provider[] aProvider = Security.getProviders();
            for (int i = 0; i < aProvider.length; i++) {
                Provider provider = aProvider[i];
                LOGGER.trace(
                        "Provider " + (i + 1) + " : " + provider.getName() + " " + provider.getInfo() + " :");
                List keyList = new ArrayList(provider.keySet());
                try {
                    Collections.sort(keyList);
                } catch (Exception e) {
                    LOGGER.trace("Provider's properties keys can't be sorted", e);
                }
                Iterator keyIterator = keyList.iterator();
                while (keyIterator.hasNext()) {
                    String key = (String) keyIterator.next();
                    LOGGER.trace(key + ": " + provider.getProperty(key));
                }
                LOGGER.trace("------------------------------------------------");
            }
        } catch (Exception e) {
            LOGGER.trace("Listing security providers failed", e);
        }
    }
}

From source file:com.joyent.manta.client.multipart.EncryptedServerSideMultipartManagerSerializationIT.java

public final void canResumeUploadWithByteArrayAndMultipleParts() throws Exception {
    final SupportedCipherDetails cipherDetails = SupportedCiphersLookupMap.INSTANCE
            .get(config.getEncryptionAlgorithm());
    final SecretKey secretKey = SecretKeyUtils.loadKey(config.getEncryptionPrivateKeyBytes(), cipherDetails);
    final EncryptedMultipartUploaSerializationHelper<ServerSideMultipartUpload> helper = new EncryptedMultipartUploaSerializationHelper<>(
            kryo, secretKey, cipherDetails, ServerSideMultipartUpload.class);
    final String name = UUID.randomUUID().toString();
    final String path = testPathPrefix + name;
    final byte[] content = RandomUtils.nextBytes(FIVE_MB + 1024);
    final byte[] content1 = Arrays.copyOfRange(content, 0, FIVE_MB + 1);
    final byte[] content2 = Arrays.copyOfRange(content, FIVE_MB + 1, FIVE_MB + 1024);

    String contentType = "application/something-never-seen-before; charset=UTF-8";
    MantaHttpHeaders headers = new MantaHttpHeaders();
    headers.setContentType(contentType);

    EncryptedMultipartUpload<ServerSideMultipartUpload> upload = multipart.initiateUpload(path, null, headers);
    MantaMultipartUploadPart part1 = multipart.uploadPart(upload, 1, content1);

    Provider provider = upload.getEncryptionState().getEncryptionContext().getCipher().getProvider();

    LOGGER.info("Testing serialization with encryption provider: {}", provider.getInfo());

    final byte[] serializedEncryptionState = helper.serialize(upload);

    EncryptedMultipartUpload<ServerSideMultipartUpload> deserializedUpload = helper
            .deserialize(serializedEncryptionState);

    MantaMultipartUploadPart part2 = multipart.uploadPart(deserializedUpload, 2, content2);
    MantaMultipartUploadTuple[] parts = new MantaMultipartUploadTuple[] { part1, part2 };
    Stream<MantaMultipartUploadTuple> partsStream = Arrays.stream(parts);

    multipart.complete(deserializedUpload, partsStream);

    try (MantaObjectInputStream in = mantaClient.getAsInputStream(path)) {
        Assert.assertEquals(in.getContentType(), contentType,
                "Set content-type doesn't match actual content type");

        int b;/*w  w  w  .  j  a v a  2 s . c  o  m*/
        int i = 0;
        while ((b = in.read()) != -1) {
            final byte expected = content[i++];

            Assert.assertEquals((byte) b, expected,
                    "Byte [" + (char) b + "] not matched at position: " + (i - 1));
        }

        if (i + 1 < content.length) {
            fail("Missing " + (content.length - i + 1) + " bytes from Manta stream");
        }
    }
}

From source file:at.tfr.securefs.Configuration.java

@PostConstruct
public void init() {

    if (log.isDebugEnabled()) {
        for (Provider p : Security.getProviders()) {
            try {
                log.debug("Provider: " + p.getClass() + ", Name=" + p.getName() + ", Info=" + p.getInfo());
                final Set<Service> services = p.getServices();
                if (services == null) {
                    log.debug("Provider has no services: " + p);
                } else {
                    for (Service s : services) {
                        log.debug("Service: " + s.getClassName() + ", " + s.getAlgorithm() + ", ");
                    }//from ww  w . jav  a 2s  .  co m
                }
            } catch (Throwable t) {
                log.info("cannot print info: Provider=" + p + " : " + t, t);
            }
        }
    }

    loadSecureFsProperties(true);

    keyAlgorithm = secConfig.getString(SECUREFS_SERVER_PFX + KEY_ALGORITHM, keyAlgorithm);
    log.info("KeyAlgorithm = " + keyAlgorithm);
    keyStrength = secConfig.getInt(SECUREFS_SERVER_PFX + KEY_STRENGTH, keyStrength);
    log.info("KeyStrength = " + keyStrength);
    iterationCount = secConfig.getInt(SECUREFS_SERVER_PFX + ITERATION_COUNT, iterationCount);
    log.info("IterationCount = " + iterationCount);
    cipherAlgorithm = secConfig.getString(SECUREFS_SERVER_PFX + CIPHER_ALGORITHM, cipherAlgorithm);
    log.info("CipherAlgorithm = " + cipherAlgorithm);
    paddingCipherAlgorithm = secConfig.getString(SECUREFS_SERVER_PFX + PADDING_CIPHER_ALGORITHM,
            paddingCipherAlgorithm);
    log.info("PaddingCipherAlgorithm = " + paddingCipherAlgorithm);
    salt = secConfig.getString(SECUREFS_SERVER_PFX + SALT, salt);
    log.info("Salt = " + salt);
    cacheName = secConfig.getString(SECUREFS_SERVER_PFX + CACHE_NAME, cacheName);
    log.info("CacheName = " + cacheName);
    restrictedToBasePath = secConfig.getBoolean(SECUREFS_SERVER_PFX + RESTRICTED_TO_BASE_PATH,
            restrictedToBasePath);
    log.info("RestrictedToBasePath = " + restrictedToBasePath);
    preProcessing = secConfig.getBoolean(SECUREFS_SERVER_PFX + PRE_PROCESSING, preProcessing);
    log.info("PreProcessing = " + preProcessing);

    test = secConfig.getBoolean(SECUREFS_SERVER_PFX + TEST, test);
    log.info("Test = " + test);

    try {
        String basePathProp = secConfig.getString(SECUREFS_SERVER_PFX + BASE_PATH);
        if (StringUtils.isNotBlank(basePathProp)) {
            basePath = Paths.get(basePathProp);
        } else {
            basePath = Files.createTempDirectory(SECUREFS);
        }
        log.info("BasePath = " + basePath);
        revokedKeysPath = basePath.resolve(REVOKED_KEYS);

    } catch (Exception e) {
        log.warn("cannot open BasePath", e);
    }

    try {
        String tmpPathProp = secConfig.getString(SECUREFS_SERVER_PFX + TMP_PATH);
        String jbossTmpPathProp = System.getProperty(JBOSS_SERVER_TEMP_DIR);
        if (StringUtils.isNotBlank(tmpPathProp)) {
            tmpPath = Paths.get(tmpPathProp);
        } else if (StringUtils.isNotBlank(jbossTmpPathProp)) {
            tmpPath = Files.createDirectories(Paths.get(jbossTmpPathProp, SECUREFS));
        } else {
            tmpPath = Files.createTempDirectory(SECUREFS);
        }
        log.info("TmpPath = " + tmpPath);

    } catch (Exception e) {
        log.warn("cannot open TmpPath", e);
    }

    try {
        schemaPath = Paths.get(secConfig.getString(SECUREFS_SERVER_PFX + SCHEMA_PATH, "/tmp"));
        log.info("SchemaPath = " + schemaPath);
    } catch (Exception e) {
        log.warn("cannot open SchemaPath", e);
    }

    try {
        log.info("ServiceModules : names=" + getServiceModules());
        getModuleConfigurations().stream().peek((m) -> log.info("\t" + m));
    } catch (Exception e) {
        log.warn("cannot read ServiceModules", e);
    }

}

From source file:org.mule.providers.ldap.LdapSASLConnector.java

protected void doInitialise() throws InitialisationException {

    // if (isForceJDK14())
    // {// w w w  . j av a 2s  .  co m
    // logger.debug("forcing JDK 1.4 SASL mode");
    Security.addProvider(new com.novell.sasl.client.SaslProvider());
    // }
    /*
     * else { Provider sunSASL = Security.getProvider("SunSASL");
     * 
     * if (sunSASL != null) { logger .debug("SunSASL implementation (JDK >=
     * 1.5) detected. Use it."); try { Sasl.setSaslClientFactory(new
     * SaslBridgeClientFactory()); } catch (RuntimeException e) {
     * logger.warn(e.toString()); } } else { logger .debug("No SunSASL
     * implementation (JDK >= 1.5 detected. Fall back to JDK 1.4 mode");
     * Security.addProvider(new com.novell.sasl.client.SaslProvider()); } }
     */

    if (logger.isDebugEnabled()) {

        Provider[] ps = Security.getProviders();
        for (int i = 0; i < ps.length; i++) {
            Provider provider = ps[i];
            logger.debug(provider.getClass() + "/" + provider.getName() + "/" + provider.getVersion() + "/"
                    + provider.getInfo());

        }
    }

    if (MECHANISM_DIGEST_EXTERNAL.equals(mechanism)) {

        try {
            if (trustAll) {
                SSLContext context = SSLContext.getInstance("TLS");
                context.init(null, trustAll ? TrustAllCertsManager.getTrustAllCertsManager() : null, null);

                // certificate_unknown
                ssf = new LDAPJSSESecureSocketFactory(context.getSocketFactory());
            } else {
                if (StringUtils.isEmpty(trustStore)) {
                    throw new InitialisationException(new IllegalArgumentException(
                            "Either trustAll value must be true or the trustStore parameter must be set"),
                            this);
                }

                File trustStoreFile = new File(trustStore);

                if (!trustStoreFile.exists() || !trustStoreFile.canRead()) {
                    throw new InitialisationException(new IllegalArgumentException("truststore file "
                            + trustStoreFile.getAbsolutePath() + " do not exist or is not readable"), this);
                }

                System.setProperty("javax.net.ssl.trustStore", trustStore);

                logger.debug("truststore set to " + trustStoreFile.getAbsolutePath());

                ssf = new LDAPJSSESecureSocketFactory();
            }
            // pix path
            // ssf = new LDAPJSSESecureSocketFactory((SSLSocketFactory)
            // SSLSocketFactory.getDefault());

            // TODO SSL<->TLS (TLS maybe require startTLS() call on lc
            // ssf = new LDAPJSSEStartTLSFactory();
        } catch (KeyManagementException e) {
            throw new InitialisationException(e, this);
        } catch (NoSuchAlgorithmException e) {
            throw new InitialisationException(e, this);
        }

    }

    super.doInitialise();
}

From source file:test.be.fedict.eid.applet.RSATest.java

@Test
public void testListSecurityProviders() throws Exception {
    Provider[] providers = Security.getProviders();
    for (Provider provider : providers) {
        LOG.debug("provider name: " + provider.getName());
        LOG.debug("provider info: " + provider.getInfo());
        Set<Service> services = provider.getServices();
        for (Service service : services) {
            LOG.debug("\tservice type: " + service.getType());
            LOG.debug("\tservice algo: " + service.getAlgorithm());
        }/*w  ww  . ja va2s. c o  m*/
    }
}