All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bitplan.mediawiki.japi.user.Crypt Maven / Gradle / Ivy

Go to download

Java library to call Mediawiki API described at http://www.mediawiki.org/wiki/API:Main_page

There is a newer version: 0.2.3
Show newest version
/**
 * Copyright (C) 2015 BITPlan GmbH
 *
 * Pater-Delp-Str. 1
 * D-47877 Willich-Schiefbahn
 *
 * http://www.bitplan.com
 * 
 * This source is part of
 * https://github.com/WolfgangFahl/Mediawiki-Japi
 * and the license for Mediawiki-Japi applies
 * 
 */
package com.bitplan.mediawiki.japi.user;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.List;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

/**
 * Encryption class to be use for password encryption for test cases
 * @author wf
 *
 */
public class Crypt {

	private char[] cypher;
	byte[] salt;

	/**
	 * @return the cypher
	 */
	public String getCypher() {
		return new String(cypher);
	}
	
	/**
	 * return the salt
	 * @return the salt
	 */
	public String getSalt() {
		return new String(salt);
	}

	/**
	 * @param cypher the cypher to set
	 */
	public void setCypher(char[] cypher) {
		this.cypher = cypher;
	}

	/**
	 * create me from a password and salt
	 * 
	 * @param pCypher
	 * @param pSalt
	 */
	Crypt(String pCypher, String pSalt) {
		this.setCypher(pCypher.toCharArray());
		this.salt = pSalt.getBytes();
	}

	/**
	 * generate a Random key
	 * @param pLength
	 * @return the reandom key with the given length
	 */
	public static String generateRandomKey(int pLength) {
    int asciiFirst = 48;
    int asciiLast = 122;
    Integer[] exceptions = { 58,59,60,61,62,63,91,92,93,94,96 };

    List exceptionsList = Arrays.asList(exceptions);
    SecureRandom random = new SecureRandom();
    StringBuilder builder = new StringBuilder();
    for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy