Example usage for org.apache.shiro.codec Base64 decode

List of usage examples for org.apache.shiro.codec Base64 decode

Introduction

In this page you can find the example usage for org.apache.shiro.codec Base64 decode.

Prototype

public static byte[] decode(byte[] base64Data) 

Source Link

Document

Decodes Base64 data into octets

Usage

From source file:br.com.criativasoft.opendevice.restapi.auth.AesRuntimeCipher.java

License:Open Source License

public String decript(String text) {
    ByteSource decrypt = cipher.decrypt(Base64.decode(text), key);
    return new String(decrypt.getBytes());
}

From source file:cn.com.rexen.ext.shiro.web.filter.authc.ForwardedX509AuthenticationFilter.java

License:Open Source License

private static List<X509Certificate> loadPEMBundle(final Reader pemBundleReader)
        throws IOException, CertificateException {
    BufferedReader br = null;//from  w w  w. jav a 2 s.c  o m
    final String malformed = "Malformed PEM X.509 Certificate Bundle";
    try {
        br = new BufferedReader(pemBundleReader);
        String line = br.readLine();
        if (!line.startsWith(PEM_BEGIN)) {
            throw new CertificateException(malformed);
        }
        final List<X509Certificate> certList = new ArrayList<X509Certificate>();
        boolean begin = false;
        boolean end = true;
        StringBuilder x509Base64 = new StringBuilder();
        CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
        while (line != null) {
            if (line.length() > 0) {
                if (line.startsWith(PEM_BEGIN)) {
                    if (!begin && end) {
                        begin = true;
                        end = false;
                        x509Base64 = new StringBuilder();
                    } else {
                        throw new CertificateException(malformed);
                    }
                } else if (line.startsWith(PEM_END)) {
                    if (begin || !end) {
                        begin = false;
                        end = true;
                        byte[] base64DecodedCert = Base64.decode(x509Base64.toString());
                        certList.add((X509Certificate) certFactory
                                .generateCertificate(new ByteArrayInputStream(base64DecodedCert)));
                    } else {
                        throw new CertificateException(malformed);
                    }
                } else if (begin && !end) {
                    x509Base64.append(line);
                }
            }
            line = br.readLine();
        }
        if (begin || !end) {
            throw new CertificateException(malformed);
        }
        return certList;
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException ignored) {
            }
        }
    }
}

From source file:cn.powerdash.libsystem.common.security.util.CryptoUtil.java

License:Open Source License

public static String decrypt(String cipherText, String key) {
    AesCipherService aesCs = new AesCipherService();
    byte[] keyBytes = CodecSupport.toBytes(key);

    ByteSource decryptedBytes = aesCs.decrypt(Base64.decode(CodecSupport.toBytes(cipherText)), keyBytes);
    return CodecSupport.toString(decryptedBytes.getBytes());
}

From source file:com.app.shiro.UserSaltedAuthenticationInfo.java

License:Open Source License

@Override
public ByteSource getCredentialsSalt() {
    return new SimpleByteSource(Base64.decode(_salt));
}

From source file:com.axelor.apps.account.service.payment.PayboxService.java

License:Open Source License

/**
 * //w  w w .j  av  a 2  s  .  c o  m
 * @param signature
 *          La signature contenu dans l'url
 * @param urlParam
 *          Liste des paramtres contenus dans l'url, priv du dernier : la signature
 * @param pubKeyPath
 *          Le chemin de la cl publique Paybox
 * @return
 * @throws Exception
 */
public boolean checkPaybox(String signature, List<String> urlParam, String pubKeyPath) throws Exception {

    String payboxParams = StringUtils.join(urlParam, "&");
    LOG.debug("Liste des variables Paybox signes : {}", payboxParams);

    //          Dj dcode par le framework
    //           String decoded = URLDecoder.decode(sign, this.CHARSET);

    byte[] sigBytes = Base64.decode(signature.getBytes(this.CHARSET));

    // lecture de la cle publique
    PublicKey pubKey = this.getPubKey(pubKeyPath);

    /** 
     * Dans le cas o le cl est au format .der
     *
     * PublicKey pubKey = this.getPubKeyDer(pubKeyPath);
    */

    // verification signature
    return this.verify(payboxParams.getBytes(), sigBytes, this.HASH_ENCRYPTION_ALGORITHM, pubKey);

}

From source file:com.blazarquant.bfp.core.security.config.FixedCookieRememberMeManager.java

License:Apache License

@Inject
public FixedCookieRememberMeManager(@Named("shiro.cipherKey") String cipherKey) {
    super();
    setCipherKey(Base64.decode(cipherKey));
}

From source file:com.cuisongliu.springboot.shiro.autoconfig.ShiroAutoConfig.java

License:Open Source License

/**
 * ?/*from w w w. j a v a 2s  .c o  m*/
 */
@Bean
public DefaultWebSecurityManager securityManager(SessionManager sessionManager, ShiroAbstractRealm realm) {
    DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
    securityManager.setRealm(realm);

    RedisManager redisManager = new RedisManager(redisHost, redisPort, redisTimeout, redisPassword);
    ShiroRedisCacheManager shiroRedisCacheManager = new ShiroRedisCacheManager(redisManager,
            springShiroProperties.getRedisCacheKey());

    securityManager.setCacheManager(shiroRedisCacheManager);

    {
        if (springShiroProperties.getEnableRememberMe()) {
            //SimpleCookie 
            SimpleCookie rememberMeCookie = new SimpleCookie(springShiroProperties.getRememberMeCookieName());
            rememberMeCookie.setHttpOnly(springShiroProperties.getRememberMeCookieHttpOnly());
            //7
            rememberMeCookie.setMaxAge(springShiroProperties.getRememberMeCookieDays() * 24 * 60 * 60);
            //rememberMe?, cipherKey??{@code Base64Test.java}
            CookieRememberMeManager rememberMeManager = new CookieRememberMeManager();
            rememberMeManager.setCipherKey(Base64.decode(springShiroProperties.getRememberMeKey()));
            rememberMeManager.setCookie(rememberMeCookie);
            //rememberMe
            securityManager.setRememberMeManager(rememberMeManager);
        }
    }

    securityManager.setSessionManager(sessionManager);
    return securityManager;
}

From source file:com.flowlogix.services.test.PrincipalSerializationTests.java

License:Apache License

@Test
public void serializer() {
    final Serializer<X> ser = new DefaultSerializer<>();
    final String encoded = Base64.encodeToString(ser.serialize(new X(15, "xxx")));
    assertEquals(new X(15, "xxx"), ser.deserialize(Base64.decode(encoded)));
}

From source file:com.ikanow.aleph2.security.db.SerializableUtils.java

License:Apache License

public static Object deserialize(String str) {
    Object value = null;/* ww w .  ja  v a2  s  .  c om*/
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decode(str));
        ObjectInputStream ois = new ObjectInputStream(bis);
        value = ois.readObject();
    } catch (Exception e) {
        logger.error("Caught exception deserializing:", e);
    }
    return value;

}

From source file:com.ning.billing.server.security.KillbillJdbcRealm.java

License:Apache License

@Override
protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token)
        throws AuthenticationException {
    final SimpleAuthenticationInfo authenticationInfo = (SimpleAuthenticationInfo) super.doGetAuthenticationInfo(
            token);/*  w  w w. j  ava2  s .c o m*/

    // We store the salt bytes in Base64 (because the JdbcRealm retrieves it as a String)
    final ByteSource base64Salt = authenticationInfo.getCredentialsSalt();
    authenticationInfo.setCredentialsSalt(ByteSource.Util.bytes(Base64.decode(base64Salt.getBytes())));

    return authenticationInfo;
}