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


Java Base64类代码示例

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


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

示例1: calculateInitialPasswordHash

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入依赖的package包/类
/**
 * Not actully a test case, just to calculate the initial password hash:
 */
@Test
public void calculateInitialPasswordHash() {
    final int salt = 0;
    final String password = "admin123";
    final byte[] hash = PasswordHash.calculateHash(salt, password);
    System.out.println("Salt:        " + salt);
    System.out.println("Password:    " + password);
    System.out.printf("Hash Base64: %s", Base64.encode(hash));
    System.out.printf("Hash:        0x%x%n", new BigInteger(hash));
    System.out.print("Hash:        ");
    for (int i = 0; i < hash.length; i++) {
        System.out.printf("\\\\%03o", Integer.valueOf(0xFF & hash[i]));
    }
    System.out.println("");
    System.out.println(Arrays.toString(hash));
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:20,代码来源:PasswordHashTest.java

示例2: saltedHash

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入依赖的package包/类
private static String saltedHash(String toHash, byte[] saltBytes) {
    Random r = new Random();
    if (saltBytes == null) {
        saltBytes = new byte[SALT_SIZE];
        r.nextBytes(saltBytes);
    }
    byte[] textBytes = toHash.getBytes();
    byte[] textWithSaltBytes = new byte[textBytes.length + saltBytes.length];
    System.arraycopy(textBytes, 0, textWithSaltBytes, 0, textBytes.length);
    System.arraycopy(saltBytes, 0, textWithSaltBytes, textBytes.length, saltBytes.length);
    byte[] hashBytes = Encryptor.hashBytes(textWithSaltBytes);
    byte[] hashWithSaltBytes = new byte[hashBytes.length + saltBytes.length];
    System.arraycopy(hashBytes, 0, hashWithSaltBytes, 0, hashBytes.length);
    System.arraycopy(saltBytes, 0, hashWithSaltBytes, hashBytes.length, saltBytes.length);
    return Base64.encode(hashWithSaltBytes);
}
 
开发者ID:timitoc,项目名称:groupicture,代码行数:17,代码来源:Encryptor.java

示例3: main

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入依赖的package包/类
public static void main(String[] args) throws IOException{
	String dirName="H:\\java\\ImageMatching-pHash(modified)\\src\\resources\\dataset";
	ByteArrayOutputStream baos = new ByteArrayOutputStream(1000);
	BufferedImage img = ImageIO.read(new File(dirName,"tempImage.jpg"));
	ImageIO.write(img, "jpg", baos);
	baos.flush();

	String base64String = Base64.encode(baos.toByteArray());
	baos.close();

	byte[] bytearray = Base64.decode(base64String);
               
               for(int i=0;i<bytearray.length;i++){
                   System.out.println(bytearray[i]);
               }
               
	BufferedImage imag = ImageIO.read(new ByteArrayInputStream(bytearray));
	ImageIO.write(imag, "jpg", new File(dirName,"snap.jpg"));
}
 
开发者ID:nowshad-sust,项目名称:ImageMatching-pHash,代码行数:20,代码来源:ConvertImage.java

示例4: user

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入依赖的package包/类
public static Map.Entry<String, String> user(HttpContext httpContext, String realm) throws AuthenticationException {
    HttpHeaders httpHeaders = httpContext.getRequestHeaders();
    String auth = httpHeaders.get(HttpHeaders.Authorization);

    if (auth == null || !auth.startsWith("Basic ")) {
        throw new BasicAuthenticationException(realm);
    }

    auth = auth.substring("Basic ".length());
    auth = new String(Base64.decode(auth));

    String[] parts = auth.split(":");

    if (parts.length != 2) {
        throw new BasicAuthenticationException(realm);
    }
    return new AbstractMap.SimpleImmutableEntry<String, String>(parts[0], parts[1]);
}
 
开发者ID:bobisjan,项目名称:adaptive-restful-api,代码行数:19,代码来源:BasicAuthentication.java

示例5: process

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入依赖的package包/类
private BeanstreamResponse process(HttpUriRequest http,
            ResponseHandler<BeanstreamResponse> responseHandler) throws IOException {
    
    HttpClient httpclient;
    if (customHttpClient != null)
        httpclient = customHttpClient;
    else
        httpclient = HttpClients.createDefault();
    // Remove newlines from base64 since they can bork the header.
    // Some base64 encoders will append a newline to the end
    String auth = Base64.encode((merchantId + ":" + apiPasscode).trim().getBytes());
    
    http.addHeader("Content-Type", "application/json");
    http.addHeader("Authorization", "Passcode " + auth);

    BeanstreamResponse responseBody = httpclient.execute(http, responseHandler);
    
    return responseBody;
}
 
开发者ID:bambora-na,项目名称:beanstream-java,代码行数:20,代码来源:HttpsConnector.java

示例6: getActualValue

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入依赖的package包/类
public Object getActualValue(String content, ValidationContext context) throws InvalidDatatypeValueException {
    byte[] decoded = Base64.decode(content);
    if (decoded == null)
        throw new InvalidDatatypeValueException("cvc-datatype-valid.1.2.1", new Object[]{content, "base64Binary"});

    return new XBase64(decoded);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:Base64BinaryDV.java

示例7: subscribeTopic

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入依赖的package包/类
private String subscribeTopic(String timeout) {
	String response = "";
	try {
		String requestURL = this.topicURL + "/events/" + this.topicname + "/mirrormakeragent/1?timeout=" + timeout
				+ "&limit=1";
		String authString = this.mechid + ":" + this.password;
		String authStringEnc = Base64.encode(authString.getBytes());
		URL url = new URL(requestURL);
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		connection.setRequestMethod("GET");
		connection.setDoOutput(true);
		connection.setRequestProperty("Authorization", "Basic " + authStringEnc);
		connection.setRequestProperty("Content-Type", "application/json");
		InputStream content = (InputStream) connection.getInputStream();
		BufferedReader in = new BufferedReader(new InputStreamReader(content));
		String line;

		while ((line = in.readLine()) != null) {
			response = response + line;
		}
		Gson g = new Gson();
		// get message as JSON String Array
		String[] topicMessage = g.fromJson(response, String[].class);
		if (topicMessage.length != 0) {
			return topicMessage[0];
		}
	} catch (Exception e) {
		return "ERROR:" + e.getMessage() + " Server Response is:" + response;
	}
	return null;
}
 
开发者ID:att,项目名称:dmaap-framework,代码行数:32,代码来源:MirrorMakerAgent.java

示例8: publishTopic

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入依赖的package包/类
private String publishTopic(String message) {
	try {
		String requestURL = this.topicURL + "/events/" + this.topicname;
		String authString = this.mechid + ":" + this.password;
		String authStringEnc = Base64.encode(authString.getBytes());
		URL url = new URL(requestURL);
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		connection.setRequestMethod("POST");
		connection.setDoOutput(true);
		connection.setRequestProperty("Authorization", "Basic " + authStringEnc);
		connection.setRequestProperty("Content-Type", "application/json");
		connection.setRequestProperty("Content-Length", Integer.toString(message.length()));
		DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
		wr.write(message.getBytes());

		InputStream content = (InputStream) connection.getInputStream();
		BufferedReader in = new BufferedReader(new InputStreamReader(content));
		String line;
		String response = "";
		while ((line = in.readLine()) != null) {
			response = response + line;
		}
		return response;

	} catch (Exception e) {
		return "ERROR:" + e.getLocalizedMessage();
	}
}
 
开发者ID:att,项目名称:dmaap-framework,代码行数:29,代码来源:MirrorMakerAgent.java

示例9: uploadImageInFolder

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入依赖的package包/类
public static void uploadImageInFolder(JSONObject parameters, JSONObject response){
    initDBHandler();
    //response.put("req_id", parameters.getInt("id"));
    //response.put("req_image", parameters.getString("image"));
    try {
        DBHandler.getInstance().uploadImageInFolder(parameters.getInt("id"), Base64.decode(parameters.getString("image")));
    } catch (SQLException ex) {
        System.out.println("EXCEPTION: " + ex.getMessage());
        response.put("detail", ex.getMessage());
        Logger.getLogger(Worker.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:timitoc,项目名称:groupicture,代码行数:13,代码来源:Worker.java

示例10: encrypt

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入依赖的package包/类
public static String encrypt(String s) throws Exception
	{
		SecretKeySpec key = new SecretKeySpec(keyBytes, ALGO);
		cipher = Cipher.getInstance(ALGO);
		cipher.init(Cipher.ENCRYPT_MODE, key);
		byte[] encVal = cipher.doFinal(s.getBytes());
		String encryptedValue = Base64.encode(encVal);
                return encryptedValue;
//return encryptedValue.substring(0, encryptedValue.length()-1);
	}
 
开发者ID:timitoc,项目名称:groupicture,代码行数:11,代码来源:Encryptor.java

示例11: decrypt

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入依赖的package包/类
public static String decrypt(String s) throws Exception
{
	SecretKeySpec key = new SecretKeySpec(keyBytes, ALGO);
	cipher = Cipher.getInstance(ALGO);
	cipher.init(Cipher.DECRYPT_MODE, key);
	byte[] b = Base64.decode(s);
	return new String(cipher.doFinal(b));
}
 
开发者ID:timitoc,项目名称:groupicture,代码行数:9,代码来源:Encryptor.java

示例12: hash

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入依赖的package包/类
public static String hash(String toHash){
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        md.update(toHash.getBytes("UTF-8"));
        byte[] digest = md.digest();
        return Base64.encode(digest);
    } catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) {
        Logger.getLogger(Encryptor.class.getName()).log(Level.SEVERE, null, ex);
    }
    throw new RuntimeException("Failed to hash String");
}
 
开发者ID:timitoc,项目名称:groupicture,代码行数:12,代码来源:Encryptor.java

示例13: checkSaltedHash

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入依赖的package包/类
public static boolean checkSaltedHash(String text, String hash) {
    try {
        byte[] hashWithSaltBytes = Base64.decode(hash);
        byte[] saltBytes = new byte[hashWithSaltBytes.length - 32];
        System.arraycopy(hashWithSaltBytes, 32, saltBytes, 0, saltBytes.length);
        String expectedHash = saltedHash(text, saltBytes);
        return expectedHash.equals(hash);

    } catch (Exception e) {
        return false;
    }
}
 
开发者ID:timitoc,项目名称:groupicture,代码行数:13,代码来源:Encryptor.java

示例14: imageToByteArray

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入依赖的package包/类
public static byte[] imageToByteArray(String imagePath)throws IOException{
    ByteArrayOutputStream baos = new ByteArrayOutputStream(1000);
    BufferedImage img = ImageIO.read(new File(imagePath));
    ImageIO.write(img, "jpg", baos);
    baos.flush();
 
    String base64String = Base64.encode(baos.toByteArray());
    baos.close();
 
    byte[] bytearray = Base64.decode(base64String);
    
    return bytearray;
}
 
开发者ID:nowshad-sust,项目名称:ImageMatching-pHash,代码行数:14,代码来源:ConvertImage.java

示例15: loadAndEncode

import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; //导入依赖的package包/类
public static String loadAndEncode(File imgFile, int maxWidth, int maxHeight) {
	try {
		final BufferedImage original = ImageIO.read(imgFile);
		final BufferedImage resized = new BufferedImage(maxWidth, maxHeight, BufferedImage.TYPE_INT_ARGB);
		final Graphics2D g = resized.createGraphics();
		
		final Image temp;
		if (original.getWidth() > original.getHeight()) {
			temp = original.getScaledInstance(-1, maxHeight, Image.SCALE_SMOOTH);
		} else {
			temp = original.getScaledInstance(maxWidth, -1, Image.SCALE_SMOOTH);
		}

		g.drawImage(temp, 
			(int) (maxWidth * 0.5 - temp.getWidth(null) * 0.5), 
			(int) (maxHeight * 0.5 - temp.getHeight(null) * 0.5),
			null
		);

		byte[] bytes;
		
		try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
			ImageIO.write(resized, "jpg", baos);
			baos.flush();
			bytes = baos.toByteArray();
		}
		
		g.dispose();
		
		return Base64.encode(bytes);
		
	} catch (IOException ex) {
		Logger.getLogger(JSONImage.class.getName())
			.log(Level.SEVERE, "Could not read image '" + imgFile.getName() + "'.", ex);
		return null;
	}
}
 
开发者ID:Pyknic,项目名称:SocialPhotoNetworkClient,代码行数:38,代码来源:ImageResizeUtil.java


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