当前位置: 首页>>代码示例>>Java>>正文


Java Password类代码示例

本文整理汇总了Java中sun.security.util.Password的典型用法代码示例。如果您正苦于以下问题:Java Password类的具体用法?Java Password怎么用?Java Password使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Password类属于sun.security.util包,在下文中一共展示了Password类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: promptForCredential

import sun.security.util.Password; //导入依赖的package包/类
private char[] promptForCredential() throws Exception {
    // Handle password supplied via stdin
    if (System.console() == null) {
        char[] importPass = Password.readPassword(System.in);
        passwords.add(importPass);
        return importPass;
    }

    int count;
    for (count = 0; count < 3; count++) {
        System.err.print(
            rb.getString("Enter.the.password.to.be.stored."));
        System.err.flush();
        char[] entered = Password.readPassword(System.in);
        passwords.add(entered);
        System.err.print(rb.getString("Re.enter.password."));
        char[] passAgain = Password.readPassword(System.in);
        passwords.add(passAgain);
        if (!Arrays.equals(entered, passAgain)) {
            System.err.println(rb.getString("They.don.t.match.Try.again"));
            continue;
        }
        return entered;
    }

    if (count == 3) {
        throw new Exception(rb.getString
            ("Too.many.failures.key.not.added.to.keystore"));
    }

    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:Main.java

示例2: getKeyPasswd

import sun.security.util.Password; //导入依赖的package包/类
private char[] getKeyPasswd(String s, String s1, char ac[])
throws Exception {
    int i = 0;
    char ac1[] = null;
    do
    {
        if(ac != null) {
            MessageFormat messageformat = new MessageFormat(rb.getString("Enter key password for <alias>"));
            Object aobj[] = {
                s
            };
            System.err.println(messageformat.format(((Object) (aobj))));
            messageformat = new MessageFormat(rb.getString("\t(RETURN if same as for <otherAlias>)"));
            Object aobj2[] = {
                s1
            };
            System.err.print(messageformat.format(((Object) (aobj2))));
        } else {
            MessageFormat messageformat1 = new MessageFormat(rb.getString("Enter key password for <alias>"));
            Object aobj1[] = {
                s
            };
            System.err.print(messageformat1.format(((Object) (aobj1))));
        }
        System.err.flush();
        ac1 = Password.readPassword(System.in);
        if(ac1 == null)
            ac1 = ac;
        i++;
    } while(ac1 == null && i < 3);
    if(ac1 == null)
        throw new Exception(rb.getString("Too many failures - try later"));
    else
        return ac1;
}
 
开发者ID:bernhardhuber,项目名称:netbeansplugins,代码行数:36,代码来源:KeyTool.java

示例3: promptForKeyPass

import sun.security.util.Password; //导入依赖的package包/类
/**
 * Prompt the user for a keypass when generating a key entry.
 * @param alias the entry we will set password for
 * @param orig the original entry of doing a dup, null if generate new
 * @param origPass the password to copy from if user press ENTER
 */
private char[] promptForKeyPass(String alias, String orig, char[] origPass) throws Exception{
    if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
        return origPass;
    } else if (!token && !protectedPath) {
        // Prompt for key password
        int count;
        for (count = 0; count < 3; count++) {
            MessageFormat form = new MessageFormat(rb.getString
                    ("Enter.key.password.for.alias."));
            Object[] source = {alias};
            System.err.println(form.format(source));
            if (orig == null) {
                System.err.print(rb.getString
                        (".RETURN.if.same.as.keystore.password."));
            } else {
                form = new MessageFormat(rb.getString
                        (".RETURN.if.same.as.for.otherAlias."));
                Object[] src = {orig};
                System.err.print(form.format(src));
            }
            System.err.flush();
            char[] entered = Password.readPassword(System.in);
            passwords.add(entered);
            if (entered == null) {
                return origPass;
            } else if (entered.length >= 6) {
                System.err.print(rb.getString("Re.enter.new.password."));
                char[] passAgain = Password.readPassword(System.in);
                passwords.add(passAgain);
                if (!Arrays.equals(entered, passAgain)) {
                    System.err.println
                        (rb.getString("They.don.t.match.Try.again"));
                    continue;
                }
                return entered;
            } else {
                System.err.println(rb.getString
                    ("Key.password.is.too.short.must.be.at.least.6.characters"));
            }
        }
        if (count == 3) {
            if (command == KEYCLONE) {
                throw new Exception(rb.getString
                    ("Too.many.failures.Key.entry.not.cloned"));
            } else {
                throw new Exception(rb.getString
                        ("Too.many.failures.key.not.added.to.keystore"));
            }
        }
    }
    return null;    // PKCS11, MSCAPI, or -protected
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:59,代码来源:Main.java

示例4: getNewPasswd

import sun.security.util.Password; //导入依赖的package包/类
/**
 * Prompts user for new password. New password must be different from
 * old one.
 *
 * @param prompt the message that gets prompted on the screen
 * @param oldPasswd the current (i.e., old) password
 */
private char[] getNewPasswd(String prompt, char[] oldPasswd)
    throws Exception
{
    char[] entered = null;
    char[] reentered = null;

    for (int count = 0; count < 3; count++) {
        MessageFormat form = new MessageFormat
            (rb.getString("New.prompt."));
        Object[] source = {prompt};
        System.err.print(form.format(source));
        entered = Password.readPassword(System.in);
        passwords.add(entered);
        if (entered == null || entered.length < 6) {
            System.err.println(rb.getString
                ("Password.is.too.short.must.be.at.least.6.characters"));
        } else if (Arrays.equals(entered, oldPasswd)) {
            System.err.println(rb.getString("Passwords.must.differ"));
        } else {
            form = new MessageFormat
                    (rb.getString("Re.enter.new.prompt."));
            Object[] src = {prompt};
            System.err.print(form.format(src));
            reentered = Password.readPassword(System.in);
            passwords.add(reentered);
            if (!Arrays.equals(entered, reentered)) {
                System.err.println
                    (rb.getString("They.don.t.match.Try.again"));
            } else {
                Arrays.fill(reentered, ' ');
                return entered;
            }
        }
        if (entered != null) {
            Arrays.fill(entered, ' ');
            entered = null;
        }
        if (reentered != null) {
            Arrays.fill(reentered, ' ');
            reentered = null;
        }
    }
    throw new Exception(rb.getString("Too.many.failures.try.later"));
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:52,代码来源:Main.java

示例5: doGenKeyPair

import sun.security.util.Password; //导入依赖的package包/类
private void doGenKeyPair(String s, String s1, String s2, int i, String s3)
throws Exception {
    if(s == null)
        s = keyAlias;
    if(keyStore.containsAlias(s)) {
        MessageFormat messageformat = new MessageFormat(rb.getString("Key pair not generated, alias <alias> already exists"));
        Object aobj[] = {
            s
        };
        throw new Exception(messageformat.format(((Object) (aobj))));
    }
    if(s3 == null)
        if(s2.equalsIgnoreCase("DSA"))
            s3 = "SHA1WithDSA";
        else
            if(s2.equalsIgnoreCase("RSA"))
                s3 = "MD5WithRSA";
            else
                throw new Exception(rb.getString("Cannot derive signature algorithm"));
    CertAndKeyGen certandkeygen = new CertAndKeyGen(s2, s3, providerName);
    X500Name x500name;
    if(s1 == null)
        x500name = getX500Name();
    else
        x500name = new X500Name(s1);
    if(verbose) {
        MessageFormat messageformat1 = new MessageFormat(rb.getString("Generating keysize bit keyAlgName key pair and self-signed certificate (sigAlgName)\n\tfor: x500Name"));
        Object aobj1[] = {
            new Integer(i), s2, s3, x500name
        };
        System.err.println(messageformat1.format(((Object) (aobj1))));
    }
    certandkeygen.generate(i);
    PrivateKey privatekey = certandkeygen.getPrivateKey();
    X509Certificate ax509certificate[] = new X509Certificate[1];
    ax509certificate[0] = certandkeygen.getSelfCertificate(x500name, validity * 24L * 60L * 60L);
    if(!token && keyPass == null) {
        int j;
        for(j = 0; j < 3 && keyPass == null; j++) {
            MessageFormat messageformat2 = new MessageFormat(rb.getString("Enter key password for <alias>"));
            Object aobj2[] = {
                s
            };
            System.err.println(messageformat2.format(((Object) (aobj2))));
            System.err.print(rb.getString("\t(RETURN if same as keystore password):  "));
            System.err.flush();
            keyPass = Password.readPassword(System.in);
            if(keyPass == null) {
                keyPass = storePass;
                continue;
            }
            if(keyPass.length < 6) {
                System.err.println(rb.getString("Key password is too short - must be at least 6 characters"));
                keyPass = null;
            }
        }
        
        if(j == 3)
            throw new Exception(rb.getString("Too many failures - key not added to keystore"));
    }
    keyStore.setKeyEntry(s, privatekey, keyPass, ax509certificate);
}
 
开发者ID:bernhardhuber,项目名称:netbeansplugins,代码行数:63,代码来源:KeyTool.java

示例6: getNewPasswd

import sun.security.util.Password; //导入依赖的package包/类
private char[] getNewPasswd(String s, char ac[])
throws Exception {
    Object obj = null;
    char ac2[] = null;
    for(int i = 0; i < 3; i++) {
        MessageFormat messageformat = new MessageFormat(rb.getString("New prompt: "));
        Object aobj[] = {
            s
        };
        System.err.print(messageformat.format(((Object) (aobj))));
        char ac1[] = Password.readPassword(System.in);
        if(ac1.length < 6)
            System.err.println(rb.getString("Password is too short - must be at least 6 characters"));
        else
            if(Arrays.equals(ac1, ac)) {
            System.err.println(rb.getString("Passwords must differ"));
            } else {
            MessageFormat messageformat1 = new MessageFormat(rb.getString("Re-enter new prompt: "));
            Object aobj1[] = {
                s
            };
            System.err.print(messageformat1.format(((Object) (aobj1))));
            ac2 = Password.readPassword(System.in);
            if(!Arrays.equals(ac1, ac2)) {
                System.err.println(rb.getString("They don't match; try again"));
            } else {
                Arrays.fill(ac2, ' ');
                return ac1;
            }
            }
        if(ac1 != null) {
            Arrays.fill(ac1, ' ');
            ac1 = null;
        }
        if(ac2 != null) {
            Arrays.fill(ac2, ' ');
            ac2 = null;
        }
    }
    
    throw new Exception(rb.getString("Too many failures - try later"));
}
 
开发者ID:bernhardhuber,项目名称:netbeansplugins,代码行数:43,代码来源:KeyTool.java

示例7: loadSourceKeyStore

import sun.security.util.Password; //导入依赖的package包/类
/**
 * Load the srckeystore from a stream, used in -importkeystore
 * @returns the src KeyStore
 */
KeyStore loadSourceKeyStore() throws Exception {

    InputStream is = null;
    File srcksfile = null;

    if (P11KEYSTORE.equalsIgnoreCase(srcstoretype) ||
            KeyStoreUtil.isWindowsKeyStore(srcstoretype)) {
        if (!NONE.equals(srcksfname)) {
            System.err.println(MessageFormat.format(rb.getString
                (".keystore.must.be.NONE.if.storetype.is.{0}"), srcstoretype));
            System.err.println();
            tinyHelp();
        }
    } else {
        srcksfile = new File(srcksfname);
            is = new FileInputStream(srcksfile);
    }

    KeyStore store;
    try {
        if (srcProviderName == null) {
            store = KeyStore.getInstance(srcstoretype);
        } else {
            store = KeyStore.getInstance(srcstoretype, srcProviderName);
        }

        if (srcstorePass == null
                && !srcprotectedPath
                && !KeyStoreUtil.isWindowsKeyStore(srcstoretype)) {
            System.err.print(rb.getString("Enter.source.keystore.password."));
            System.err.flush();
            srcstorePass = Password.readPassword(System.in);
            passwords.add(srcstorePass);
        }

        // always let keypass be storepass when using pkcs12
        if (P12KEYSTORE.equalsIgnoreCase(srcstoretype)) {
            if (srckeyPass != null && srcstorePass != null &&
                    !Arrays.equals(srcstorePass, srckeyPass)) {
                MessageFormat form = new MessageFormat(rb.getString(
                    "Warning.Different.store.and.key.passwords.not.supported.for.PKCS12.KeyStores.Ignoring.user.specified.command.value."));
                Object[] source = {"-srckeypass"};
                System.err.println(form.format(source));
                srckeyPass = srcstorePass;
            }
        }

        store.load(is, srcstorePass);   // "is" already null in PKCS11
    } finally {
        if (is != null) {
            is.close();
        }
    }

    if (srcstorePass == null
            && !KeyStoreUtil.isWindowsKeyStore(srcstoretype)) {
        // anti refactoring, copied from printNoIntegrityWarning(),
        // but change 2 lines
        System.err.println();
        System.err.println(rb.getString
            (".WARNING.WARNING.WARNING."));
        System.err.println(rb.getString
            (".The.integrity.of.the.information.stored.in.the.srckeystore."));
        System.err.println(rb.getString
            (".WARNING.WARNING.WARNING."));
        System.err.println();
    }

    return store;
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:75,代码来源:Main.java

示例8: promptForKeyPass

import sun.security.util.Password; //导入依赖的package包/类
/**
 * Prompt the user for a keypass when generating a key entry.
 * @param alias the entry we will set password for
 * @param orig the original entry of doing a dup, null if generate new
 * @param origPass the password to copy from if user press ENTER
 */
private char[] promptForKeyPass(String alias, String orig, char[] origPass) throws Exception{
    if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
        return origPass;
    } else if (!token) {
        // Prompt for key password
        int count;
        for (count = 0; count < 3; count++) {
            MessageFormat form = new MessageFormat(rb.getString
                    ("Enter.key.password.for.alias."));
            Object[] source = {alias};
            System.err.println(form.format(source));
            if (orig == null) {
                System.err.print(rb.getString
                        (".RETURN.if.same.as.keystore.password."));
            } else {
                form = new MessageFormat(rb.getString
                        (".RETURN.if.same.as.for.otherAlias."));
                Object[] src = {orig};
                System.err.print(form.format(src));
            }
            System.err.flush();
            char[] entered = Password.readPassword(System.in);
            passwords.add(entered);
            if (entered == null) {
                return origPass;
            } else if (entered.length >= 6) {
                System.err.print(rb.getString("Re.enter.new.password."));
                char[] passAgain = Password.readPassword(System.in);
                passwords.add(passAgain);
                if (!Arrays.equals(entered, passAgain)) {
                    System.err.println
                        (rb.getString("They.don.t.match.Try.again"));
                    continue;
                }
                return entered;
            } else {
                System.err.println(rb.getString
                    ("Key.password.is.too.short.must.be.at.least.6.characters"));
            }
        }
        if (count == 3) {
            if (command == KEYCLONE) {
                throw new Exception(rb.getString
                    ("Too.many.failures.Key.entry.not.cloned"));
            } else {
                throw new Exception(rb.getString
                        ("Too.many.failures.key.not.added.to.keystore"));
            }
        }
    }
    return null;    // PKCS11
}
 
开发者ID:openjdk,项目名称:jdk7-jdk,代码行数:59,代码来源:KeyTool.java


注:本文中的sun.security.util.Password类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。