1.Nettyä¸çchannelReadåmessageReceivedçåºå«
2.关于java中DecimalFormat的源码问题。
3.å¦ä½å®ç°ç¨javascriptå®ç°rsaå 解å¯
4.我想把java文件先加密然后打包,源码jq on 事件源码请高手指教怎么加密,源码app成品源码有那种好的源码ollyice 源码调试加密算法吗?
Nettyä¸çchannelReadåmessageReceivedçåºå«
éè¦ç¼è§£ç çæä¼å»ç¨messageReceivedï¼ä¸è¬é½æ¯ä½¿ç¨ChannelReadæ¥è¯»åçã读ä¸ä¸
SimpleChannelInboundHandlerçæºä»£ç ä½ å°±ç¥éäºï¼æ³åä¸å¹é ï¼ä¸ä¼è°ç¨messageReceivedçã
å¦ï¼å¦æä½ ç¹å«ç¹å«æ³ç¨SimpleChannelInboundHandlerï¼ä½ å¯ä»¥è¿æ ·æï¼public classYouTCPServerHandler extends SimpleChannelInboundHandler<ByteBuf>{ ...}
å ä¸ºä½ æ²¡æåè¿ä»»ä½çç¼ç 解ç ï¼æä»¥ä½ çæ³åæ¯ByteBufï¼è¿æ ·ä½ è¯å®å¯ä»¥ä½¿ç¨messageReceivedæ¥æ¥æ¶å°æ¶æ¯äºãå¦æè¿ä¸æç½ï¼å»ºè®®ä½ å»çä¸ä¸nettyèªå¸¦çsampleï¼éé¢æ个æ±é¶ä¹çä¾åï¼serveråclientä¼ éçBigInteger对象ï¼æ以就ç¨çæ¯
SimpleChannelInboundHandler<BigInteger>ã没æç»è¿ä»»ä½ç¼ç 解ç çé£å°±è¯å®æ¯ByteBuf对象ã
关于java中DecimalFormat的问题。
把newSalary转为double型,源码东森电影 源码然后再format就好了,源码#NAME?看源码就会知道,源码String类型是源码不被允许的public final StringBuffer format(Object number,StringBuffer toAppendTo,
FieldPosition pos) {
if (number instanceof Long || number instanceof Integer ||
number instanceof Short || number instanceof Byte ||
number instanceof AtomicInteger ||
number instanceof AtomicLong ||
(number instanceof BigInteger &&
((BigInteger)number).bitLength () < )) {
return format(((Number)number).longValue(), toAppendTo, pos);
} else if (number instanceof BigDecimal) {
return format((BigDecimal)number, toAppendTo, pos);
} else if (number instanceof BigInteger) {
return format((BigInteger)number, toAppendTo, pos);
} else if (number instanceof Number) {
return format(((Number)number).doubleValue(), toAppendTo, pos);
} else {
throw new IllegalArgumentException("Cannot format given Object as a Number");
}
}
å¦ä½å®ç°ç¨javascriptå®ç°rsaå 解å¯
å ·ä½å®ç°æè·¯å¦ä¸ï¼1ãæå¡ç«¯çæå ¬é¥ä¸ç§é¥ï¼ä¿åã
2ã客æ·ç«¯å¨è¯·æ±å°ç»å½é¡µé¢åï¼éæºçæä¸å符串ã
3ãåæ¤éæºå符串ä½ä¸ºå¯é¥å å¯å¯ç ï¼åç¨ä»æå¡ç«¯è·åå°çå ¬é¥å å¯çæçéæºå符串ã
4ãå°æ¤ä¸¤æ®µå¯æä¼ å ¥æå¡ç«¯ï¼æå¡ç«¯ç¨ç§é¥è§£åºéæºå符串ï¼åç¨æ¤ç§é¥è§£åºå å¯çå¯æã
è¿å ¶ä¸æä¸ä¸ªå ³é®æ¯è§£å³æå¡ç«¯çå ¬é¥ï¼ä¼ å ¥å®¢æ·ç«¯ï¼å®¢æ·ç«¯ç¨æ¤å ¬é¥å å¯å符串åï¼ååè½å¨æå¡ç«¯ç¨ç§é¥è§£åºã
æ¤æå³ä¸ºå®ç°æ¤æ¥èä½ã
å å¯ç®æ³ä¸ºRSAï¼
1ãæå¡ç«¯çRSA javaå®ç°ã
/***
*/
package com.sunsoft.struts.util;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.math.BigInteger;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.RSAPublicKeySpec;
import javax.crypto.Cipher;
/**
* RSA å·¥å ·ç±»ãæä¾å å¯ï¼è§£å¯ï¼çæå¯é¥å¯¹çæ¹æ³ã
* éè¦å°ment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class RSA {
/
*** BigInteger.ZERO
*/
private static final BigInteger ZERO = BigInteger.ZERO;
/
*** BigInteger.ONE
*/
private static final BigInteger ONE = BigInteger.ONE;
/
*** Pseudo BigInteger.TWO
*/
private static final BigInteger TWO = new BigInteger("2");
private BigInteger myKey;
private BigInteger myMod;
private int blockSize;
public RSA (BigInteger key, BigInteger n, int b) {
myKey = key;
myMod = n;
blockSize = b;
}
public void encodeFile (String filename) {
byte[] bytes = new byte[blockSize / 8 + 1];
byte[] temp;
int tempLen;
InputStream is = null;
FileWriter writer = null;
try {
is = new FileInputStream(filename);
writer = new FileWriter(filename + ".enc");
}
catch (FileNotFoundException e1){
System.out.println("File not found: " + filename);
}
catch (IOException e1){
System.out.println("File not found: " + filename + ".enc");
}
/
*** Write encoded message to 'filename'.enc
*/
try {
while ((tempLen = is.read(bytes, 1, blockSize / 8)) > 0) {
for (int i = tempLen + 1; i < bytes.length; ++i) {
bytes[i] = 0;
}
writer.write(encodeDecode(new BigInteger(bytes)) + " ");
}
}
catch (IOException e1) {
System.out.println("error writing to file");
}
/
*** Close input stream and file writer
*/
try {
is.close();
writer.close();
}
catch (IOException e1) {
System.out.println("Error closing file.");
}
}
public void decodeFile (String filename) {
FileReader reader = null;
OutputStream os = null;
try {
reader = new FileReader(filename);
os = new FileOutputStream(filename.replaceAll(".enc", ".dec"));
}
catch (FileNotFoundException e1) {
if (reader == null)
System.out.println("File not found: " + filename);
else
System.out.println("File not found: " + filename.replaceAll(".enc", "dec"));
}
BufferedReader br = new BufferedReader(reader);
int offset;
byte[] temp, toFile;
StringTokenizer st = null;
try {
while (br.ready()) {
st = new StringTokenizer(br.readLine());
while (st.hasMoreTokens()){
toFile = encodeDecode(new BigInteger(st.nextToken())).toByteArray();
System.out.println(toFile.length + " x " + (blockSize / 8));
if (toFile[0] == 0 && toFile.length != (blockSize / 8)) {
temp = new byte[blockSize / 8];
offset = temp.length - toFile.length;
for (int i = toFile.length - 1; (i <= 0) && ((i + offset) <= 0); --i) {
temp[i + offset] = toFile[i];
}
toFile = temp;
}
/*if (toFile.length != ((blockSize / 8) + 1)){
temp = new byte[(blockSize / 8) + 1];
System.out.println(toFile.length + " x " + temp.length);
for (int i = 1; i < temp.length; i++) {
temp[i] = toFile[i - 1];
}
toFile = temp;
}
else
System.out.println(toFile.length + " " + ((blockSize / 8) + 1));*/
os.write(toFile);
}
}
}
catch (IOException e1) {
System.out.println("Something went wrong");
}
/
*** close data streams
*/
try {
os.close();
reader.close();
}
catch (IOException e1) {
System.out.println("Error closing file.");
}
}
/
*** Performs <tt>base</tt>^<sup><tt>pow</tt></sup> within the modular
* domain of <tt>mod</tt>.
*
* @param base the base to be raised
* @param pow the power to which the base will be raisded
* @param mod the modular domain over which to perform this operation
* @return <tt>base</tt>^<sup><tt>pow</tt></sup> within the modular
* domain of <tt>mod</tt>.
*/
public BigInteger encodeDecode(BigInteger base) {
BigInteger a = ONE;
BigInteger s = base;
BigInteger n = myKey;
while (!n.equals(ZERO)) {
if(!n.mod(TWO).equals(ZERO))
a = a.multiply(s).mod(myMod);
s = s.pow(2).mod(myMod);
n = n.divide(TWO);
}
return a;
}
}
在这里提供两个版本的RSA算法JAVA实现的代码下载:
1. 来自于 /code.aspx?ID= 的RSA算法实现源代码包:
/rsa/
参考资料:/product/showarticle.asp?id=