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


Java Base64.encode方法代码示例

本文整理汇总了Java中org.apache.axiom.om.util.Base64.encode方法的典型用法代码示例。如果您正苦于以下问题:Java Base64.encode方法的具体用法?Java Base64.encode怎么用?Java Base64.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.axiom.om.util.Base64的用法示例。


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

示例1: getPasswordToStore

import org.apache.axiom.om.util.Base64; //导入方法依赖的package包/类
private String getPasswordToStore(String password, String passwordHashMethod)
        throws DirectoryServerManagerException {

    String passwordToStore = password;

    if (passwordHashMethod != null) {
        try {

            if (passwordHashMethod.equals(LDAPServerManagerConstants.PASSWORD_HASH_METHOD_PLAIN_TEXT)) {
                return passwordToStore;
            }

            MessageDigest messageDigest = MessageDigest.getInstance(passwordHashMethod);
            byte[] digestValue = messageDigest.digest(password.getBytes(StandardCharsets.UTF_8));
            passwordToStore = "{" + passwordHashMethod + "}" + Base64.encode(digestValue);

        } catch (NoSuchAlgorithmException e) {
            throw new DirectoryServerManagerException("Invalid hashMethod", e);
        }
    }

    return passwordToStore;
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:24,代码来源:LDAPServerStoreManager.java

示例2: addKeyStore

import org.apache.axiom.om.util.Base64; //导入方法依赖的package包/类
public void addKeyStore(byte[] content, String filename, String password, String provider,
                        String type, String pvtkspass) throws java.lang.Exception {
    try {
        String data = Base64.encode(content);
        AddKeyStore request = new AddKeyStore();
        request.setFileData(data);
        request.setFilename(filename);
        request.setPassword(password);
        request.setProvider(provider);
        request.setType(type);
        request.setPvtkeyPass(pvtkspass);
        stub.addKeyStore(request);
    } catch (java.lang.Exception e) {
        log.error("Error in adding keystore", e);
        throw e;
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:18,代码来源:KeyStoreAdminClient.java

示例3: preparePassword

import org.apache.axiom.om.util.Base64; //导入方法依赖的package包/类
public static String preparePassword(String password, String saltValue) throws UserStoreException {
    try {
        String digestInput = password;
        if (saltValue != null) {
            digestInput = password + saltValue;
        }
        String digsestFunction = Util.getRealmConfig().getUserStoreProperties()
                .get(JDBCRealmConstants.DIGEST_FUNCTION);
        if (digsestFunction != null) {

            if (digsestFunction.equals(UserCoreConstants.RealmConfig.PASSWORD_HASH_METHOD_PLAIN_TEXT)) {
                return password;
            }

            MessageDigest dgst = MessageDigest.getInstance(digsestFunction);
            byte[] byteValue = dgst.digest(digestInput.getBytes(Charset.forName("UTF-8")));
            password = Base64.encode(byteValue);
        }
        return password;
    } catch (NoSuchAlgorithmException e) {
        log.error(e.getMessage(), e);
        throw new UserStoreException(e.getMessage(), e);
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:25,代码来源:Util.java

示例4: getSaltValue

import org.apache.axiom.om.util.Base64; //导入方法依赖的package包/类
public static String getSaltValue() {
    String saltValue = null;
    if ("true".equals(realmConfig.getUserStoreProperties().get(JDBCRealmConstants.STORE_SALTED_PASSWORDS))) {
        try {
            SecureRandom secureRandom = SecureRandom.getInstance(SHA_1_PRNG);
            byte[] bytes = new byte[16];
            //secureRandom is automatically seeded by calling nextBytes
            secureRandom.nextBytes(bytes);
            saltValue = Base64.encode(bytes);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("SHA1PRNG algorithm could not be found.", e);
        }

    }
    return saltValue;
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:17,代码来源:Util.java

示例5: importCertToStore

import org.apache.axiom.om.util.Base64; //导入方法依赖的package包/类
public void importCertToStore(String filename, byte[] content, String keyStoreName)
        throws java.lang.Exception {
    try {
        String data = Base64.encode(content);
        ImportCertToStore request = new ImportCertToStore();
        request.setFileName(filename);
        request.setFileData(data);
        request.setKeyStoreName(keyStoreName);
        stub.importCertToStore(request);
    } catch (java.lang.Exception e) {
        log.error("Error in importing cert to store.", e);
        throw e;
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:15,代码来源:KeyStoreAdminClient.java

示例6: doHash

import org.apache.axiom.om.util.Base64; //导入方法依赖的package包/类
/**
 * @param value
 * @return
 * @throws UserStoreException
 */
public static String doHash(String value) throws UserStoreException {
    try {
        String digsestFunction = "SHA-256";
        MessageDigest dgst = MessageDigest.getInstance(digsestFunction);
        byte[] byteValue = dgst.digest(value.getBytes());
        return Base64.encode(byteValue);
    } catch (NoSuchAlgorithmException e) {
        log.error(e.getMessage(), e);
        throw new UserStoreException(e.getMessage(), e);
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:17,代码来源:Utils.java

示例7: encryptPlainText

import org.apache.axiom.om.util.Base64; //导入方法依赖的package包/类
/**
 * @param plainText Cipher text to be encrypted
 * @return Returns the encrypted text
 * @throws IdentityUserStoreMgtException Encryption failed
 */
public static String encryptPlainText(String plainText) throws IdentityUserStoreMgtException {

    if (cipher == null) {
        initializeKeyStore();
    }

    try {
        return Base64.encode(cipher.doFinal((plainText.getBytes())));
    } catch (GeneralSecurityException e) {
        String errMsg = "Failed to generate the cipher text";
        throw new IdentityUserStoreMgtException(errMsg, e);
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:19,代码来源:SecondaryUserStoreConfigurationUtil.java

示例8: updateSecondaryUserStore

import org.apache.axiom.om.util.Base64; //导入方法依赖的package包/类
/**
 * Encrypts the secondary user store configuration
 *
 * @param secondaryStoreDocument OMElement of respective file path
 * @param cipher                 Cipher object read for super-tenant's key store
 * @throws UserStoreConfigurationDeployerException If update operation failed
 */
private void updateSecondaryUserStore(OMElement secondaryStoreDocument, Cipher cipher) throws
        UserStoreConfigurationDeployerException {
    String className = secondaryStoreDocument.getAttributeValue(new QName(UserStoreConfigurationConstants.PROPERTY_CLASS));
    ArrayList<String> encryptList = getEncryptPropertyList(className);
    Iterator<?> ite = secondaryStoreDocument.getChildrenWithName(new QName(UserStoreConfigurationConstants.PROPERTY));
    while (ite.hasNext()) {
        OMElement propElem = (OMElement) ite.next();

        if (propElem != null && (propElem.getText() != null)) {
            String propertyName = propElem.getAttributeValue(new QName(UserStoreConfigurationConstants.PROPERTY_NAME));

            OMAttribute encryptedAttr = propElem.getAttribute(new QName(UserStoreConfigurationConstants
                    .PROPERTY_ENCRYPTED));
            if (encryptedAttr == null) {
                boolean encrypt = encryptList.contains(propertyName) || isEligibleTobeEncrypted(propElem);
                if (encrypt) {
                    OMAttribute encryptAttr = propElem.getAttribute(new QName(UserStoreConfigurationConstants.PROPERTY_ENCRYPT));
                    if (encryptAttr != null) {
                        propElem.removeAttribute(encryptAttr);
                    }

                    try {
                        String cipherText = Base64.encode(cipher.doFinal((propElem.getText().getBytes())));
                        propElem.setText(cipherText);
                        propElem.addAttribute(UserStoreConfigurationConstants.PROPERTY_ENCRYPTED, "true", null);
                    } catch (GeneralSecurityException e) {
                        String errMsg = "Encryption in secondary user store failed";
                        throw new UserStoreConfigurationDeployerException(errMsg, e);
                    }
                }
            }
        }
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:42,代码来源:UserStoreConfigurationDeployer.java

示例9: setEnvironment

import org.apache.axiom.om.util.Base64; //导入方法依赖的package包/类
/**
 * Set up the environment.
 */
@BeforeClass(alwaysRun = true)
public void setEnvironment() throws Exception {

    init("freshdesk-connector-2.0.1-SNAPSHOT");
    esbRequestHeadersMap.put("Accept-Charset", "UTF-8");
    esbRequestHeadersMap.put("Content-Type", "application/json");
    apiRequestHeadersMap.putAll(esbRequestHeadersMap);
    String authString = connectorProperties.getProperty("apiKey") + ":X";
    String authorizationHeader = "Basic " + Base64.encode(authString.getBytes());
    apiRequestHeadersMap.put("Authorization", authorizationHeader);
}
 
开发者ID:wso2-extensions,项目名称:esb-connector-freshdesk,代码行数:15,代码来源:FreshdeskConnectorIntegrationTest.java

示例10: getBase64EncodedBasicAuthHeader

import org.apache.axiom.om.util.Base64; //导入方法依赖的package包/类
/**
 * To get Base64 encoded username:password for basic authentication header
 *
 * @param username username
 * @param password password
 * @return Base64 encoded value of username:password
 */
private String getBase64EncodedBasicAuthHeader(String username, String password) {

    String concatenatedCredential = username + ":" + password;
    byte[] byteValue = concatenatedCredential.getBytes(Charsets.UTF_8);
    String encodedAuthHeader = Base64.encode(byteValue);
    encodedAuthHeader = "Basic " + encodedAuthHeader;
    return encodedAuthHeader;
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:16,代码来源:JsonMessageModule.java

示例11: addAdminPassword

import org.apache.axiom.om.util.Base64; //导入方法依赖的package包/类
private void addAdminPassword(ServerEntry adminEntry, String password,
                              PasswordAlgorithm algorithm,
                              final boolean kdcEnabled)
        throws DirectoryServerException {

    try {
        String passwordToStore = "{" + algorithm.getAlgorithmName() + "}";
        if (algorithm != PasswordAlgorithm.PLAIN_TEXT && !kdcEnabled) {
            MessageDigest md = MessageDigest.getInstance(algorithm.getAlgorithmName());
            md.update(password.getBytes());
            byte[] bytes = md.digest();
            String hash = Base64.encode(bytes);
            passwordToStore = passwordToStore + hash;

        } else {

            if (kdcEnabled) {
                logger.warn(
                        "KDC enabled. Enforcing passwords to be plain text. Cause - KDC " +
                                "cannot operate with hashed passwords.");
            }

            passwordToStore = password;
        }

        adminEntry.put("userPassword", passwordToStore.getBytes());

    } catch (NoSuchAlgorithmException e) {
        throwDirectoryServerException("Could not find matching hash algorithm - " +
                algorithm.getAlgorithmName(), e);
    }

}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:34,代码来源:ApacheDirectoryPartitionManager.java

示例12: getBase64EncodedBasicAuthHeader

import org.apache.axiom.om.util.Base64; //导入方法依赖的package包/类
public static String getBase64EncodedBasicAuthHeader(String userName, String password) {
    String concatenatedCredential = userName + ":" + password;
    byte[] byteValue = concatenatedCredential.getBytes();
    String encodedAuthHeader = Base64.encode(byteValue);
    encodedAuthHeader = "Basic " + encodedAuthHeader;
    return encodedAuthHeader;
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:8,代码来源:BasicAuthUtil.java

示例13: getStringFromDatahandler

import org.apache.axiom.om.util.Base64; //导入方法依赖的package包/类
/**
 * Converts the given .datahandler to a string
 *
 * @return string
 */
public static String getStringFromDatahandler(DataHandler dataHandler) {
    try {
        InputStream inStream;
        if (dataHandler == null) {
            return "";
        }
        inStream = dataHandler.getDataSource().getInputStream();
        byte[] data = IOUtils.getStreamAsByteArray(inStream);
        return Base64.encode(data);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:19,代码来源:ConverterUtil.java

示例14: getBase64Content

import org.apache.axiom.om.util.Base64; //导入方法依赖的package包/类
public InputStream getBase64Content() throws SOAPException {
    byte[] rawData = getRawContentBytes();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        Base64.encode(rawData, 0, rawData.length, out);
        return new ByteArrayInputStream(out.toByteArray());
    } catch (IOException e) {
        throw new SOAPException(e);
    }
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:11,代码来源:AttachmentPartImpl.java

示例15: testSetBase64Content

import org.apache.axiom.om.util.Base64; //导入方法依赖的package包/类
@Validated @Test
public void testSetBase64Content() {
    try {
        MessageFactory factory = MessageFactory.newInstance();
        SOAPMessage msg = factory.createMessage();
        AttachmentPart ap = msg.createAttachmentPart();

        String urlString = "http://ws.apache.org/images/project-logo.jpg";
        if (isNetworkedResourceAvailable(urlString)) {
            URL url = new URL(urlString);
            DataHandler dh = new DataHandler(url);
            //Create InputStream from DataHandler's InputStream
            InputStream is = dh.getInputStream();

            byte buf[] = IOUtils.getStreamAsByteArray(is);
            //Setting Content via InputStream for image/jpeg mime type
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            Base64.encode(buf, 0, buf.length, bos);
            buf = bos.toByteArray();
            InputStream stream = new ByteArrayInputStream(buf);
            ap.setBase64Content(stream, "image/jpeg");

            //Getting Content.. should return InputStream object
            InputStream r = ap.getBase64Content();
            if (r != null) {
                if (r instanceof InputStream) {
                    //InputStream object was returned (ok)
                } else {
                    fail("Unexpected object was returned");
                }
            }
        }
    } catch (Exception e) {
        fail("Exception: " + e);
    }
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:37,代码来源:AttachmentTest.java


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