使用pirum管理私有的Pear库

1、先装pirm。
pear channel-discover pear.pirum-project.org
pear install pirum/Pirum

2、配置nginx放置pear虚拟主机,root路径为:/path/to/pear
2.1、在/path/to/pear下建立pirum文件,内容为:


pear.pirum-project.org

Pirum PEAR channel

pirum
http://pear.pirum-project.org/

2.2、pirum build /path/to/pear

3、装备php库文件,比如
3.1、库文件目录准备package.xml文件。
3.2、编辑php文件;
3.3、修改package.xml文件
3.4、使用pear package打包成.tgz文件
3.5、使用pirum add /path/to/pear xxxx.tgz

4、使用pear库
4.1、访问私有的pear web地址,上面有例子

JAVA实现和PHP兼容的hash_pbkdf2函数

PHP:

使用内置函数:hash_pbkdf2();

PHP代码如下:


JAVA代码如下:

import java.io.*;
import java.net.*;
import java.math.BigInteger;


import javax.crypto.*;
import javax.crypto.spec.*;


static public String hash_pbkdf2(String algorithm, String password, String salt, int iterations, int len) throws Exception {
  PBEKeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray(), salt.getBytes(), iterations, len * 4);
  SecretKeyFactory kFactory = SecretKeyFactory.getInstance(algorithm);
  SecretKey key = kFactory.generateSecret(pbeKeySpec);
  byte[] res = key.getEncoded();
  return toHex(res);
}

private static String toHex(byte[] array){
  BigInteger bi = new BigInteger(1, array);
  String hex = bi.toString(16);
  int paddingLength = (array.length * 2) - hex.length();
  if(paddingLength > 0)
    return String.format("%0" + paddingLength + "d", 0) + hex;
  else
    return hex;
}


hash_pbkdf2(“PBKDF2WithHmacSHA1”, password, salt, 1024, 32);

这时PHP和JAVA输出结果一致

最简单的flash上传文件代码

package
{
	import flash.display.*;
	import flash.text.*;
	import flash.events.DataEvent;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.SecurityErrorEvent;
	import flash.external.ExternalInterface;
	import flash.media.Camera;
	import flash.media.Microphone;
	import flash.net.XMLSocket;
	import flash.net.FileReference;
	import flash.net.URLRequest;
	import flash.net.URLVariables;
	import flash.events.MouseEvent;

	public class uploadify extends Sprite {

	private var xmlSocket:XMLSocket;
	private var fileRef:FileReference;
	private var url:String = "/path/to/upload";
	private var request:URLRequest = new URLRequest(url);
	private var param:Object = root.loaderInfo.parameters; // 取得FlashVars后面的所有参数
	
	public function uploadify():void {
		this.height = 25;
		this.width = 65;
		ExternalInterface.call("onLog",url);
		ExternalInterface.marshallExceptions = true;

		fileRef = new FileReference();
		fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onError);
		fileRef.addEventListener(IOErrorEvent.IO_ERROR,onIoError);
		fileRef.addEventListener(Event.SELECT,onSelect);
		fileRef.addEventListener(Event.OPEN,onUpload);
		fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,onComplete);
		ExternalInterface.call("onReady");

		var btn:Sprite = new Sprite();
		btn.graphics.beginFill(0xFFCC00);
		btn.graphics.drawRect(-100, -100, 1000,1000);
		this.addChild(btn);

		var text1:TextField = new TextField();
		text1.htmlText = param["text"];
		text1.selectable = false;
		text1.autoSize = TextFieldAutoSize.LEFT;
		text1.border = false;

		this.addChild(text1);

		text1.addEventListener(MouseEvent.CLICK,mouseOverListener);

	}

	private function mouseOverListener(e:MouseEvent):void{
		fileRef.browse();
	}

	private function onSelect(e:Event):void{
		url = param["url"];
		request = new URLRequest(url);
		fileRef.upload(request);
	}

	private function onComplete(e:DataEvent):void{
		ExternalInterface.call("onComplete",e.data.toString());
	}

	private function onUpload(e:Event):void{
		ExternalInterface.call("onUpload",e.toString());
	}

	private function onIoError(e:IOErrorEvent):void{
		ExternalInterface.call("onError",e.toString());
	}

	private function onError(e:SecurityErrorEvent):void{
		ExternalInterface.call("onError",e.toString());
	}

}

源码下载:uploadify