List of usage examples for org.apache.commons.net.util Base64 decode
public byte[] decode(byte[] pArray)
From source file:com.znsx.util.licence.LicenceUtil.java
/** * ???//from w w w. ja v a 2s . co m * * @param data * ?? * @param publicKeyString * ??base64? * @param signature * base64???? * @return * @throws Exception */ public static boolean verify(String data, String publicKeyString, String signature) throws Exception { // ??? // BASE64Decoder decoder = new BASE64Decoder(); // byte[] bytes = decoder.decodeBuffer(publicKeyString); Base64 base64 = new Base64(); byte[] bytes = base64.decode(publicKeyString.getBytes("utf8")); X509EncodedKeySpec keySpec = new X509EncodedKeySpec(bytes); PublicKey publicKey = KeyFactory.getInstance("DSA").generatePublic(keySpec); // ? Signature sign = Signature.getInstance("DSA"); sign.initVerify(publicKey); sign.update(data.getBytes("utf8")); // return sign.verify(decoder.decodeBuffer(signature)); return sign.verify(base64.decode(signature.getBytes("utf8"))); }
From source file:com.znsx.util.licence.LicenceUtil.java
/** * C#?????46?//from ww w.ja v a 2 s . c om * * @param sign * base64???? * @return ??? * @throws Exception * @author huangbuji * <p /> * Create at 2014-2-13 ?10:38:46 */ public static byte[] changeDSANet2java(String sign) throws Exception { Base64 base64 = new Base64(); byte tx[] = base64.decode(sign.getBytes("utf8")); byte[] tx_new = new byte[46]; tx_new[0] = 48; tx_new[1] = 44; tx_new[2] = 2; tx_new[3] = 20; for (int x = 0; x < 20; x++) { tx_new[x + 4] = tx[x]; } tx_new[24] = 2; tx_new[25] = 20; for (int x = 20; x < 40; x++) { tx_new[x + 6] = tx[x]; } return tx_new; }
From source file:com.znsx.util.licence.LicenceUtil.java
/** * ?????// www . java 2s . c o m * * @param data * ?? * @param privateKey * ???base64? * @return base64???? * @throws Exception */ public static String sign(String data, String privateKeyString) throws Exception { Base64 base64 = new Base64(); // ???? // BASE64Decoder decoder = new BASE64Decoder(); // byte[] bytes = decoder.decodeBuffer(privateKeyString); byte[] bytes = base64.decode(privateKeyString.getBytes("utf8")); PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(bytes); PrivateKey privateKey = KeyFactory.getInstance("DSA").generatePrivate(keySpec); // ??? Signature signature = Signature.getInstance("DSA"); signature.initSign(privateKey); signature.update(data.getBytes("utf8")); // return new BASE64Encoder().encode(signature.sign()); return new String(base64.encode(signature.sign()), "utf8"); }
From source file:com.znsx.util.licence.LicenceUtil.java
/** * ???/*from w w w . j a v a2s .c om*/ * * @param data * ?? * @param publicKey * 2 * @param signature * base64???? * @return * @throws Exception * @author huangbuji * <p /> * Create at 2014-2-12 ?5:37:18 */ public static boolean verifyBinKey(String data, byte[] publicKey, String signature) throws Exception { Base64 base64 = new Base64(); X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicKey); PublicKey pub = KeyFactory.getInstance("DSA").generatePublic(keySpec); // ? Signature sign = Signature.getInstance("DSA"); sign.initVerify(pub); sign.update(data.getBytes("utf8")); // return sign.verify(decoder.decodeBuffer(signature)); return sign.verify(base64.decode(signature.getBytes("utf8"))); }