1.å¦ä½å®ç°ç¨javascriptå®ç°rsaå 解å¯
2.三种大数相乘算法
3.Nettyä¸çchannelReadåmessageReceivedçåºå«
4.我想把java文件先加密然后打包,源码请高手指教怎么加密,源码社区论坛 论坛源码 php有那种好的源码圆点消消乐源码加密算法吗?
5.关于java中DecimalFormat的问题。
å¦ä½å®ç°ç¨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=关于java中DecimalFormat的问题。
把newSalary转为double型,源码网投源码分享然后再format就好了,源码天果商城源码看源码就会知道,源码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");
}
}
2024-11-21 00:342171人浏览
2024-11-21 00:272150人浏览
2024-11-21 00:181402人浏览
2024-11-21 00:161145人浏览
2024-11-20 23:28576人浏览
2024-11-20 23:111945人浏览
1.扫码点餐源码系统怎么开发?扫码点餐源码系统怎么开发? 要开发扫码点餐系统,需要以下主要步骤:1. 确定需求:首先需要明确系统的功能和需求,例如支持哪些支付方式、支持菜单的分类和搜索、菜品的下单
1.神经猫是用什么语言写的2.免费H5制作平台有哪些?宝藏网站,呼之欲出~3.微信H5页面制作流程?神经猫是用什么语言写的 “围住神经猫”是个老游戏。年7月日起,这款小游戏在微信朋友圈疯传。已知最