• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Base64类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getSamplePrivateKey

import org.apache.axiom.om.util.Base64; //导入依赖的package包/类
public static PrivateKey getSamplePrivateKey() throws Exception {
    // Read in the key into a String
    StringBuilder pkcs8Lines = new StringBuilder();
    BufferedReader rdr = new BufferedReader(new StringReader(PRIVATE_KEY));
    String line;
    while ((line = rdr.readLine()) != null) {
        pkcs8Lines.append(line);
    }

    // Remove the "BEGIN" and "END" lines, as well as any whitespace

    String pkcs8Pem = pkcs8Lines.toString();
    pkcs8Pem = pkcs8Pem.replace("-----BEGIN PRIVATE KEY-----", "");
    pkcs8Pem = pkcs8Pem.replace("-----END PRIVATE KEY-----", "");
    pkcs8Pem = pkcs8Pem.replaceAll("\\s+", "");

    // Base64 decode the result

    byte[] pkcs8EncodedBytes = Base64.decode(pkcs8Pem);

    // extract the private key

    PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(pkcs8EncodedBytes);
    KeyFactory kf = KeyFactory.getInstance("RSA");
    return kf.generatePrivate(keySpec);
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:27,代码来源:ReadCertStoreSampleUtil.java


示例2: 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


示例3: generateThumbPrint

import org.apache.axiom.om.util.Base64; //导入依赖的package包/类
/**
 * Generate thumbprint of certificate
 *
 * @param encodedCert Base64 encoded certificate
 * @return Certificate thumbprint
 * @throws java.security.NoSuchAlgorithmException Unsupported hash algorithm
 */
public static String generateThumbPrint(String encodedCert) throws NoSuchAlgorithmException {

    if (encodedCert != null) {
        MessageDigest digestValue = null;
        digestValue = MessageDigest.getInstance("SHA-1");
        byte[] der = Base64.decode(encodedCert);
        digestValue.update(der);
        byte[] digestInBytes = digestValue.digest();
        String publicCertThumbprint = hexify(digestInBytes);
        return publicCertThumbprint;
    } else {
        String errorMsg = "Invalid encoded certificate: \'NULL\'";
        log.debug(errorMsg);
        throw new IllegalArgumentException(errorMsg);
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:24,代码来源:IdentityApplicationManagementUtil.java


示例4: getCertData

import org.apache.axiom.om.util.Base64; //导入依赖的package包/类
/**
 * @param encodedCert
 * @return
 * @throws CertificateException
 */
public static CertData getCertData(String encodedCert) throws CertificateException {

    if (encodedCert != null) {
        byte[] bytes = Base64.decode(encodedCert);
        CertificateFactory factory = CertificateFactory.getInstance("X.509");
        X509Certificate cert = (X509Certificate) factory
                .generateCertificate(new ByteArrayInputStream(bytes));
        Format formatter = new SimpleDateFormat("dd/MM/yyyy");
        return fillCertData(cert, formatter);
    } else {
        String errorMsg = "Invalid encoded certificate: \'NULL\'";
        log.debug(errorMsg);
        throw new IllegalArgumentException(errorMsg);
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:21,代码来源:IdentityApplicationManagementUtil.java


示例5: 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


示例6: fillCertData

import org.apache.axiom.om.util.Base64; //导入依赖的package包/类
private CertData fillCertData(X509Certificate cert, String alise, Format formatter)
        throws CertificateEncodingException {
    CertData certData = null;

    if (includeCert) {
        certData = new CertDataDetail();
    } else {
        certData = new CertData();
    }
    certData.setAlias(alise);
    certData.setSubjectDN(cert.getSubjectDN().getName());
    certData.setIssuerDN(cert.getIssuerDN().getName());
    certData.setSerialNumber(cert.getSerialNumber());
    certData.setVersion(cert.getVersion());
    certData.setNotAfter(formatter.format(cert.getNotAfter()));
    certData.setNotBefore(formatter.format(cert.getNotBefore()));
    certData.setPublicKey(Base64.encode(cert.getPublicKey().getEncoded()));

    if (includeCert) {
        ((CertDataDetail) certData).setCertificate(cert);
    }

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


示例7: 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


示例8: 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


示例9: testProcessLocalInvalidTokenException

import org.apache.axiom.om.util.Base64; //导入依赖的package包/类
@Test
public void testProcessLocalInvalidTokenException() throws Exception{

    initCommonMocks();
    setMockHttpSession();
    setMockAuthenticationContext();
    setMockIWAAuthenticationUtil();
    setMockUserCoreUtil();

    mockSession.setAttribute(IWAConstants.KERBEROS_TOKEN, Base64.encode("invalidKerberosTokenString".getBytes()));
    when(IWAAuthenticationUtil.processToken(any(byte[].class))).thenThrow(new GSSException(0));
    try {
        iwaLocalAuthenticator.processAuthenticationResponse(
                mockHttpRequest, mockHttpResponse, mockAuthenticationContext);
        Assert.fail("Response processed with invalid kerberos token");
    } catch (AuthenticationFailedException e) {
        Assert.assertTrue(e.getMessage().contains("Error while processing the GSS Token"),
                "Exception message has changed or exception thrown from an unintended code segment.");
    }
}
 
开发者ID:wso2-extensions,项目名称:identity-local-auth-iwa-kerberos,代码行数:21,代码来源:IWAAuthenticatorTest.java


示例10: testLocalUserNotFoundInTokenException

import org.apache.axiom.om.util.Base64; //导入依赖的package包/类
@Test
public void testLocalUserNotFoundInTokenException() throws Exception {

    initCommonMocks();
    setMockHttpSession();
    setMockAuthenticationContext();
    setMockIWAAuthenticationUtil();
    setMockUserCoreUtil();

    mockSession.setAttribute(IWAConstants.KERBEROS_TOKEN, Base64.encode(token));
    when(IWAAuthenticationUtil.processToken(any(byte[].class))).thenReturn(null);

    try {
        iwaLocalAuthenticator.processAuthenticationResponse(
                mockHttpRequest, mockHttpResponse, mockAuthenticationContext);
        Assert.fail("Response processed when authenticated user is not found in the gss token");
    } catch (AuthenticationFailedException e) {
        Assert.assertTrue(e.getMessage().contains("Unable to extract authenticated user from Kerberos Token"),
                "Exception message has changed or exception thrown from an unintended code segment.");
    }
}
 
开发者ID:wso2-extensions,项目名称:identity-local-auth-iwa-kerberos,代码行数:22,代码来源:IWAAuthenticatorTest.java


示例11: testLocalUserNotFoundInUserStoreException

import org.apache.axiom.om.util.Base64; //导入依赖的package包/类
@Test
public void testLocalUserNotFoundInUserStoreException() throws Exception {

    initCommonMocks();
    setMockHttpSession();
    setMockAuthenticationContext();
    setMockIWAAuthenticationUtil();
    setMockUserCoreUtil();

    mockSession.setAttribute(IWAConstants.KERBEROS_TOKEN, Base64.encode(token));
    when(IWAAuthenticationUtil.processToken(any(byte[].class))).thenReturn("[email protected]");
    when(mockUserStoreManager.isExistingUser(anyString())).thenReturn(false);

    try {
        iwaLocalAuthenticator.processAuthenticationResponse(
                mockHttpRequest, mockHttpResponse, mockAuthenticationContext);
        Assert.fail("Response processed when authenticated user is not found in the gss token");
    } catch (AuthenticationFailedException e) {
        Assert.assertTrue(e.getMessage().contains("not found in the user store of tenant"));
    }
}
 
开发者ID:wso2-extensions,项目名称:identity-local-auth-iwa-kerberos,代码行数:22,代码来源:IWAAuthenticatorTest.java


示例12: testLocalIsExistingUserException

import org.apache.axiom.om.util.Base64; //导入依赖的package包/类
@Test
public void testLocalIsExistingUserException() throws Exception {

    initCommonMocks();
    setMockHttpSession();
    setMockAuthenticationContext();
    setMockIWAAuthenticationUtil();
    setMockUserCoreUtil();

    mockSession.setAttribute(IWAConstants.KERBEROS_TOKEN, Base64.encode(token));
    when(IWAAuthenticationUtil.processToken(any(byte[].class))).thenReturn("[email protected]");
    when(mockUserStoreManager.isExistingUser(anyString())).thenThrow(new UserStoreException());

    try {
        iwaLocalAuthenticator.processAuthenticationResponse(
                mockHttpRequest, mockHttpResponse, mockAuthenticationContext);
        Assert.fail("Response processed with user store exception");
    } catch (AuthenticationFailedException e) {
        Assert.assertTrue(e.getMessage().contains("IWALocalAuthenticator failed to find the user in the userstore"));
    }
}
 
开发者ID:wso2-extensions,项目名称:identity-local-auth-iwa-kerberos,代码行数:22,代码来源:IWAAuthenticatorTest.java


示例13: testProcessLocalAuthenticationResponse

import org.apache.axiom.om.util.Base64; //导入依赖的package包/类
@Test
public void testProcessLocalAuthenticationResponse() throws Exception{

    initCommonMocks();
    setMockHttpSession();
    setMockAuthenticationContext();
    setMockIWAAuthenticationUtil();
    setMockUserCoreUtil();

    mockSession.setAttribute(IWAConstants.KERBEROS_TOKEN, Base64.encode(token));
    when(mockUserStoreManager.isExistingUser(anyString())).thenReturn(true);

    when(IWAAuthenticationUtil.processToken(token)).thenReturn("[email protected]");

    iwaLocalAuthenticator.processAuthenticationResponse(
            mockHttpRequest, mockHttpResponse, mockAuthenticationContext);
    Assert.assertEquals(authenticatedUser.getUserName(), "wso2");
}
 
开发者ID:wso2-extensions,项目名称:identity-local-auth-iwa-kerberos,代码行数:19,代码来源:IWAAuthenticatorTest.java


示例14: testInvalidFederatedAuthConfigs

import org.apache.axiom.om.util.Base64; //导入依赖的package包/类
@Test (dataProvider = "provideInvalidAuthenticatorProperties")
public void testInvalidFederatedAuthConfigs(Map<String, String> propertyMap, String errorMsg) throws Exception {

    setMockHttpSession();
    setMockIWAAuthenticationUtil();

    when(mockAuthenticationContext.getAuthenticatorProperties()).thenReturn(propertyMap);
    mockSession.setAttribute(IWAConstants.KERBEROS_TOKEN, Base64.encode(token));
    when(mockHttpRequest.getSession(anyBoolean())).thenReturn(mockSession);
    when(mockHttpRequest.getSession()).thenReturn(mockSession);

    try {
        iwaFederatedAuthenticator.processAuthenticationResponse(
                mockHttpRequest, mockHttpResponse, mockAuthenticationContext);
        Assert.fail("Authentication response processed with incorrect configs");
    } catch (AuthenticationFailedException e) {
        Assert.assertTrue(e.getMessage().contains(errorMsg), "Wrong exception thrown for given configs");
    }
}
 
开发者ID:wso2-extensions,项目名称:identity-local-auth-iwa-kerberos,代码行数:20,代码来源:IWAAuthenticatorTest.java


示例15: testCreateCredentialExceptions

import org.apache.axiom.om.util.Base64; //导入依赖的package包/类
@Test
public void testCreateCredentialExceptions() throws Exception {

    setMockHttpSession();
    setMockIWAAuthenticationUtil();

    Map<String, String> map = new HashMap<>();
    map.put(SPN_NAME, SPN_NAME_VALUE);
    map.put(SPN_PASSWORD, SPN_PASSWORD_VALUE);
    map.put(USER_STORE_DOMAINS, USER_STORE_DOMAINS_VALUE);

    when(mockAuthenticationContext.getAuthenticatorProperties()).thenReturn(map);
    mockSession.setAttribute(IWAConstants.KERBEROS_TOKEN, Base64.encode(token));
    when(mockHttpRequest.getSession(anyBoolean())).thenReturn(mockSession);
    when(mockHttpRequest.getSession()).thenReturn(mockSession);

    when(IWAAuthenticationUtil.createCredentials(anyString(), any(char[].class))).thenThrow(new GSSException(0));

    try {
        iwaFederatedAuthenticator.processAuthenticationResponse(
                mockHttpRequest, mockHttpResponse, mockAuthenticationContext);
        Assert.fail("Authentication response processed without creating GSSCredentials");
    } catch (AuthenticationFailedException e) {
        Assert.assertTrue(e.getMessage().contains("Cannot create kerberos credentials for server"));
    }
}
 
开发者ID:wso2-extensions,项目名称:identity-local-auth-iwa-kerberos,代码行数:27,代码来源:IWAAuthenticatorTest.java


示例16: setBase64Content

import org.apache.axiom.om.util.Base64; //导入依赖的package包/类
/**
 * Sets the content of this attachment part from the Base64 source InputStream and sets the
 * value of the Content-Type header to the value contained in contentType, This method would
 * first decode the base64 input and write the resulting raw bytes to the attachment. A
 * subsequent call to getSize() may not be an exact measure of the content size.
 *
 * @param content - the base64 encoded data to add to the attachment part contentType - the
 *                value to set into the Content-Type header
 * @throws SOAPException - if there is an error in setting the content java.lang.NullPointerException
 *                       - if content is null
 */
public void setBase64Content(InputStream content, String contentType) throws SOAPException {
    if (content == null) {
        throw new SOAPException("Content is null");
    }
    OutputStream outputStream = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int read;
    try {
        while ((read = content.read(buffer, 0, buffer.length)) > 0) {
            outputStream.write(buffer, 0, read);
        }
        String contentString = outputStream.toString();
        if (Base64.isValidBase64Encoding(contentString)) {
            setContent(Base64.decode(contentString), contentType);
        } else {
            throw new SOAPException("Not a valid Base64 encoding");
        }
    } catch (IOException ex) {
        throw new SOAPException(ex);
    }
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:33,代码来源:AttachmentPartImpl.java


示例17: decodeCertificate

import org.apache.axiom.om.util.Base64; //导入依赖的package包/类
/**
 * Generate thumbprint of certificate
 *
 * @param encodedCert Base64 encoded certificate
 * @return Decoded <code>Certificate</code>
 * @throws java.security.cert.CertificateException Error when decoding certificate
 */
public static Certificate decodeCertificate(String encodedCert) throws CertificateException {

    if (encodedCert != null) {
        byte[] bytes = Base64.decode(encodedCert);
        CertificateFactory factory = CertificateFactory.getInstance("X.509");
        X509Certificate cert = (X509Certificate) factory
                .generateCertificate(new ByteArrayInputStream(bytes));
        return cert;
    } else {
        String errorMsg = "Invalid encoded certificate: \'NULL\'";
        log.debug(errorMsg);
        throw new IllegalArgumentException(errorMsg);
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:22,代码来源:IdentityApplicationManagementUtil.java


示例18: fillCertData

import org.apache.axiom.om.util.Base64; //导入依赖的package包/类
/**
 * @param cert
 * @param formatter
 * @return
 * @throws CertificateEncodingException
 */
private static CertData fillCertData(X509Certificate cert, Format formatter)
        throws CertificateEncodingException {

    CertData certData = new CertData();
    certData.setSubjectDN(cert.getSubjectDN().getName());
    certData.setIssuerDN(cert.getIssuerDN().getName());
    certData.setSerialNumber(cert.getSerialNumber());
    certData.setVersion(cert.getVersion());
    certData.setNotAfter(formatter.format(cert.getNotAfter()));
    certData.setNotBefore(formatter.format(cert.getNotBefore()));
    certData.setPublicKey(Base64.encode(cert.getPublicKey().getEncoded()));
    return certData;
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:20,代码来源:IdentityApplicationManagementUtil.java


示例19: 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


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StatCrafting类代码示例发布时间:2022-05-22
下一篇:
Java Cookie类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap