针对node.js-求Md5withRsaphp、python、或者nodejs的实现,或者给讲讲原理?和nodejsmd5解密这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展5、PHP-将
针对node.js - 求Md5withRsa php 、python、或者nodejs的实现,或者给讲讲原理?和nodejs md5解密这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展5、PHP-将浮点数转为整数 php 浮点数比较 php 浮点数精度 php 浮点数格式、elasticseatch 2.x Master-eligible node、Data node、Client node、Tribe node、HDFS essay 2 - Clarify Name Node / Checkpoint Node/ Backup Node、node.js – node -bash:/usr/sbin / node:没有这样的文件或目录等相关知识,希望可以帮助到你。
本文目录一览:- node.js - 求Md5withRsa php 、python、或者nodejs的实现,或者给讲讲原理?(nodejs md5解密)
- 5、PHP-将浮点数转为整数 php 浮点数比较 php 浮点数精度 php 浮点数格式
- elasticseatch 2.x Master-eligible node、Data node、Client node、Tribe node
- HDFS essay 2 - Clarify Name Node / Checkpoint Node/ Backup Node
- node.js – node -bash:/usr/sbin / node:没有这样的文件或目录
node.js - 求Md5withRsa php 、python、或者nodejs的实现,或者给讲讲原理?(nodejs md5解密)
客户接口是使用的java实现,验证使用的md5withrsa,拆开看都理解,放到一块就懵逼了,求讲解!!!!
附java的实现方式:
package main; import java.security.KeyFactory; import java.security.KeyPair; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.PublicKey; import java.security.Signature; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.security.SecureRandom; public class main { /** * 生成秘钥 */ public static void makeKey() { String KEY_ALGORITHM = "rsa"; java.security.KeyPairGenerator keygen; try { keygen = java.security.KeyPairGenerator .getInstance(KEY_ALGORITHM ); SecureRandom secrand = new SecureRandom(); secrand.setSeed("tmriPayment".getBytes()); // 初始化随机产生器 keygen.initialize(1024); KeyPair keys = keygen.genKeyPair(); RSAPublicKey pubkey = (RSAPublicKey) keys.getPublic(); RSAPrivateKey prikey = (RSAPrivateKey) keys.getPrivate(); String pubKeyStr= Base64Util.encodeBase64(pubkey.getEncoded());//得到公钥 并做base64编码 String priKeyStr= Base64Util.encodeBase64(prikey.getEncoded());//得到私钥 并做base64编码 System.out.println("公钥:"+ pubKeyStr); System.out.println("私钥:"+ priKeyStr); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 加密 * @return */ public static String encodeData() { try { byte[] data = "fdfdfsdfdfd".getBytes(); String privateKey = "MIICXAIBAAKBgQDOF3dzQpPVIvHrx2qwszcv9Cw5XhCEyuRTy+HDPD684NSGGGnL"+ "34cLc1BCEjlT3v9H81SigvSUDB++YbMcZOrRFT+MAt22yi98BcRP60vgVixfTCCI"+ "lc39b6G6I6ac5BUfOKwdUKNUnCLvcojshmtGezcEYGocMziOIwXIdBXErQIDAQAB"+ "AoGANlycRovuQM9J7v6YFun/Cagnri4wv0ZhefUSpRQUHHBVvtVbuspIbe3J4tO5"+ "yXTN86Ws0n0mlJKqIObWfwvjoDADNeEWFXUI5YKyEnpnvvZwTo1JjrDy8QJpGe94"+ "yNebfGLKyZtIc/zLq9sFboyqNCtn2hu7IsG2g4SGe9BFcsUCQQDnrc6yXG6jmFC/"+ "7HFqXj5NtQc72vYbIjf32yG8W1D1j3ghZZwtUkIa8g3WMxFrYW9DFMzTDi3/mPSd"+ "1A9OG89DAkEA47oFZj6xf7gzDbHDdKX/S9ehjQjP2q6V7SYXnhdEwioxjJpj9qrP"+ "SKQg8A9m4nUl2FXJ2spxApotHoKHqTGFTwJBAIkcohGJBqmnQVL0mgK7l9/hXVCd"+ "O72/OKRlecfBu1449H2/ZvijkB/mVS4Jtyt31KM8siPOZoa4fTzS/ePaLYUCQDHj"+ "LY2hjFbzblPArpXeS5g8y8pOtOIuPu/t2Vyrskdq4OHxbJa8Ap7iPcj5RsuzaDAF"+ "UywYDzvHtLyrUbbR/2cCQGbbIWDLPtzHzI7QumtabHq9M5zUgvtXDksnOltcEDSX"+ "aBoGSbpRcPcGFfFMY+fd/kdmEambYn+270DNHPvqljU="; byte[] keyBytes; keyBytes = Base64Util.decodeBase64(privateKey); PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); PrivateKey priKey = keyFactory.generatePrivate(pkcs8KeySpec); Signature signature = Signature.getInstance("MD5withRSA"); signature.initSign(priKey); signature.update(data);//data为要生成签名的源数据字节数组 return Base64Util.encodeBase64(Base64Util.encodeBase64(signature.sign()).getBytes()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }//对私钥做base64解码 return ""; } /** * 解密 * @return */ public static Boolean decodeData(String msg) { String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMrfAeCg5zyHJKs269vMywoMYwKWGfBbk31K44g0ZLg8YN4c9jOH4hyAYkhN5mWY69Q8Sb82OAlxBXMY1zQshKk6kzZGOrYDQOt/bvVg6kPdf9IgtWky4YaCVSR2C0zYCviz+pHXJrbTeyVVLmbaxsr2lEjamBoDcfM1uE9hj83QIDAQAB"; try { byte[] data = "fdfdfsdfdfd".getBytes(); byte[] publicKey1 = Base64Util.decodeBase64(publicKey);//对提供的公钥做base64解码 byte[] sign = Base64Util.decodeBase64( new String(Base64Util.decodeBase64(msg)));//签名需要做二次base64解码 X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicKey1); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); PublicKey pubKey = keyFactory.generatePublic(keySpec); Signature signature = Signature.getInstance("MD5withRSA"); signature.initVerify(pubKey); signature.update(data); return signature.verify(sign); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }//对私钥做base64解码 return false; } public static void main(String[] args) throws Exception { // TODO Auto-generated method stub //makeKey(); String msg = encodeData(); //System.out.println(msg); //String msg = "ZlBGVnVXQm1YVjhhWDhGbVVYV24raEJzRVB1WFAycUhKdVIwbGl3azY5T2VKWHBkMDlpL1U5aGYwcEVvK1h0M0RNMFNsRTNQM1pYazFyT25xblZwTStRZmJhVGVPUXBsZ0ozZVFKemFnaWt5dzNvUXRNZC81RGQ4RGlSR3pqUmRhOFd2OCt1ekRiakZBdWtqeGg3Y1plTEdTT2ppQ08rcFVqOUQxZXh6ZG1VPQ=="; //Boolean data = decodeData(msg); //System.out.println(data); } }
回复内容:
客户接口是使用的java实现,验证使用的md5withrsa,拆开看都理解,放到一块就懵逼了,求讲解!!!!
附java的实现方式:
package main; import java.security.KeyFactory; import java.security.KeyPair; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.PublicKey; import java.security.Signature; import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPublicKey; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.security.SecureRandom; public class main { /** * 生成秘钥 */ public static void makeKey() { String KEY_ALGORITHM = "rsa"; java.security.KeyPairGenerator keygen; try { keygen = java.security.KeyPairGenerator .getInstance(KEY_ALGORITHM ); SecureRandom secrand = new SecureRandom(); secrand.setSeed("tmriPayment".getBytes()); // 初始化随机产生器 keygen.initialize(1024); KeyPair keys = keygen.genKeyPair(); RSAPublicKey pubkey = (RSAPublicKey) keys.getPublic(); RSAPrivateKey prikey = (RSAPrivateKey) keys.getPrivate(); String pubKeyStr= Base64Util.encodeBase64(pubkey.getEncoded());//得到公钥 并做base64编码 String priKeyStr= Base64Util.encodeBase64(prikey.getEncoded());//得到私钥 并做base64编码 System.out.println("公钥:"+ pubKeyStr); System.out.println("私钥:"+ priKeyStr); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 加密 * @return */ public static String encodeData() { try { byte[] data = "fdfdfsdfdfd".getBytes(); String privateKey = "MIICXAIBAAKBgQDOF3dzQpPVIvHrx2qwszcv9Cw5XhCEyuRTy+HDPD684NSGGGnL"+ "34cLc1BCEjlT3v9H81SigvSUDB++YbMcZOrRFT+MAt22yi98BcRP60vgVixfTCCI"+ "lc39b6G6I6ac5BUfOKwdUKNUnCLvcojshmtGezcEYGocMziOIwXIdBXErQIDAQAB"+ "AoGANlycRovuQM9J7v6YFun/Cagnri4wv0ZhefUSpRQUHHBVvtVbuspIbe3J4tO5"+ "yXTN86Ws0n0mlJKqIObWfwvjoDADNeEWFXUI5YKyEnpnvvZwTo1JjrDy8QJpGe94"+ "yNebfGLKyZtIc/zLq9sFboyqNCtn2hu7IsG2g4SGe9BFcsUCQQDnrc6yXG6jmFC/"+ "7HFqXj5NtQc72vYbIjf32yG8W1D1j3ghZZwtUkIa8g3WMxFrYW9DFMzTDi3/mPSd"+ "1A9OG89DAkEA47oFZj6xf7gzDbHDdKX/S9ehjQjP2q6V7SYXnhdEwioxjJpj9qrP"+ "SKQg8A9m4nUl2FXJ2spxApotHoKHqTGFTwJBAIkcohGJBqmnQVL0mgK7l9/hXVCd"+ "O72/OKRlecfBu1449H2/ZvijkB/mVS4Jtyt31KM8siPOZoa4fTzS/ePaLYUCQDHj"+ "LY2hjFbzblPArpXeS5g8y8pOtOIuPu/t2Vyrskdq4OHxbJa8Ap7iPcj5RsuzaDAF"+ "UywYDzvHtLyrUbbR/2cCQGbbIWDLPtzHzI7QumtabHq9M5zUgvtXDksnOltcEDSX"+ "aBoGSbpRcPcGFfFMY+fd/kdmEambYn+270DNHPvqljU="; byte[] keyBytes; keyBytes = Base64Util.decodeBase64(privateKey); PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); PrivateKey priKey = keyFactory.generatePrivate(pkcs8KeySpec); Signature signature = Signature.getInstance("MD5withRSA"); signature.initSign(priKey); signature.update(data);//data为要生成签名的源数据字节数组 return Base64Util.encodeBase64(Base64Util.encodeBase64(signature.sign()).getBytes()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }//对私钥做base64解码 return ""; } /** * 解密 * @return */ public static Boolean decodeData(String msg) { String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDMrfAeCg5zyHJKs269vMywoMYwKWGfBbk31K44g0ZLg8YN4c9jOH4hyAYkhN5mWY69Q8Sb82OAlxBXMY1zQshKk6kzZGOrYDQOt/bvVg6kPdf9IgtWky4YaCVSR2C0zYCviz+pHXJrbTeyVVLmbaxsr2lEjamBoDcfM1uE9hj83QIDAQAB"; try { byte[] data = "fdfdfsdfdfd".getBytes(); byte[] publicKey1 = Base64Util.decodeBase64(publicKey);//对提供的公钥做base64解码 byte[] sign = Base64Util.decodeBase64( new String(Base64Util.decodeBase64(msg)));//签名需要做二次base64解码 X509EncodedKeySpec keySpec = new X509EncodedKeySpec(publicKey1); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); PublicKey pubKey = keyFactory.generatePublic(keySpec); Signature signature = Signature.getInstance("MD5withRSA"); signature.initVerify(pubKey); signature.update(data); return signature.verify(sign); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }//对私钥做base64解码 return false; } public static void main(String[] args) throws Exception { // TODO Auto-generated method stub //makeKey(); String msg = encodeData(); //System.out.println(msg); //String msg = "ZlBGVnVXQm1YVjhhWDhGbVVYV24raEJzRVB1WFAycUhKdVIwbGl3azY5T2VKWHBkMDlpL1U5aGYwcEVvK1h0M0RNMFNsRTNQM1pYazFyT25xblZwTStRZmJhVGVPUXBsZ0ozZVFKemFnaWt5dzNvUXRNZC81RGQ4RGlSR3pqUmRhOFd2OCt1ekRiakZBdWtqeGg3Y1plTEdTT2ppQ08rcFVqOUQxZXh6ZG1VPQ=="; //Boolean data = decodeData(msg); //System.out.println(data); } }
5、PHP-将浮点数转为整数 php 浮点数比较 php 浮点数精度 php 浮点数格式
1、使用强制类型转换
首先PHP支持如下所示的数据类型:
<span>1. </span>Integer (整数) <span>2. </span>Float (浮点数) <span>3. </span>String (字符串) <span>4. </span>Boolean (布尔值) <span>5. </span>Array (数组) <span>6. </span>Object (对象)
此外还有两个特殊的类型:NULL(空)、resource(资源)。
注:
1. 没有被赋值、已经被重置或者被赋值为特殊值NULL的变量就是NULL类型的变量。
2. 特定的内置函数(例如数据库函数)将返回resource类型的变量。
接着可以使用类似C语言的强制类型转换,例如
<span><?php </span><span>$a</span>=<span>6.66666</span>; <span>$b</span>=(integer)<span>$a</span>; <span>echo</span><span>$b</span>;</span>
将输出一个6,直接舍去了小数部分
立即学习“PHP免费学习笔记(深入)”;
2、使用float floor ( float value) 函数
舍去法取整,返回不大于 value 的下一个整数,将 value 的小数部分舍去取整。floor() 返回的类型仍然是 float,因为float 值的范围通常比 integer 要大。
echo <span>floor</span>(<span>4.3</span>); <span>// 输出4 </span> echo <span>floor</span>(<span>9.999</span>); <span>// 输出9</span>
3、使用float ceil ( float value) 函数
进一法取整,返回不小于 value 的下一个整数,value 如果有小数部分则进一位。ceil() 返回的类型仍然是 float,因为float 值的范围通常比 integer 要大。
echo <span>ceil</span>(<span>4.3</span>); <span>// 输出5 </span> echo <span>ceil</span>(<span>9.999</span>); <span>// 输出10</span>
4、使用float round ( float val [, int precision])函数
对浮点数进行四舍五入,返回将 val 根据指定精度 precision(十进制小数点后数字的数目)进行四舍五入的结果。precision 也可以是负数或零(默认值)。
echo <span>round</span>(<span>3.4</span>); <span>// 输出3 </span> echo <span>round</span>(<span>3.5</span>); <span>// 输出4 </span> echo <span>round</span>(<span>3.6</span>); <span>// 输出4 </span> echo <span>round</span>(<span>3.6</span>, <span>0</span>); <span>// 输出4 </span> echo <span>round</span>(<span>1.95583</span>, <span>2</span>); <span>// 输出1.96 </span> echo <span>round</span>(<span>1241757</span>, -<span>3</span>); <span>// 输出1242000 </span> echo <span>round</span>(<span>5.045</span>, <span>2</span>); <span>// 输出5.04 </span> echo <span>round</span>(<span>5.055</span>, <span>2</span>); <span>// 输出5.06</span>
以上就介绍了5、PHP-将浮点数转为整数,包括了php,浮点数方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
elasticseatch 2.x Master-eligible node、Data node、Client node、Tribe node
- Master-eligible node
- 已node.master设置为true(默认)节点,这使得它有资格被选为主节点,控制集群。
- Data node
- 有node.data设置为true(默认值)的节点。数据节点保存数据和执行数据相关的操作,如CRUD,搜索和汇总。
- Client node
- 客户端节点需要满足node.master和node.data都设置为false。它可以未持有数据,也不成为主节点。它表现为一种“智能路由器”和用于转发集群级请求到主节点和与数据相关的请求(例如搜索)到相应的数据节点。
- Tribe node
- 落节点,是一种特殊类型的客户端节点可以连接到多个集群,并执行所有连接集群搜索等操作。 通过配置tribe.*来设置
默认情况下一个节点既是主节点(master)和数据(data)节点。这是小群很方便,但是,随着集群的增长,它要考虑从专用数据节点分离专用的主节点资格就变得很重要。
通常搜索请求或批量索引可能涉及到不同的数据节点上保存的数据,协调节点将请求转发到哪个保存数据的数据节点。每个数据节点本地执行的请求,其结果返回到协调节点。在收集阶段,协调节点减少每个数据节点的结果转换成一个单一的全局结果集。 所以协调节点将消耗更大的CPU和内存。
懒得翻译
https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html
谢谢
HDFS essay 2 - Clarify Name Node / Checkpoint Node/ Backup Node
为什么想用英文写了?我获取知识、技术的大部分途径都是通过英文,所以按照自己的理解用英文写下来也比较容易,另外,很多term都是不能翻译的,如果要持续学习技术和知识,那就不但要习惯去阅读,听,还要写,说。可惜从IBM出来后,很少有机会和人去说了,只能写了。就当提高自己英文水平吧
I am going to explain how Secondary Name Node in this article. It is not called SNN any more but Checkpoint node which is more precise.
FS Image & Edit log
Edit log is an append-only file which stores the metadata changes for durability. When client issues a command like ''create file'',''chmod'' and ''rename'' , NN will write this operation ( the command itself and the data) to Edit log as an edit entry / log which is uniquely identified by an ID , we called transaction ID as each operation is considered a transaction. Transacttion ID is an auto-increment variable. NN will also apply this to the in-memory medatadata structure. The form of the entry looks like below. During run time, NN does not write directly to fsimage as writing to fsimage is a time-consuming operation.
tranID: 7
put
''/xx/xx/log.txt'',rwx------, ricky, ricky, 1024, $timestamp.....
tranID: 8
chmod 777
''/xx/xx/log.txt''
FS Image is the metadata file of HDFS namespace in NN . It is always outdated because NN does not write it frequently. Actually, when NN starts up, it will read FS image and merge Edit log to generate a new FS Image, the old one and Edit logs will be deleted. Imaging if there are many edit entries accumulated along the time(months), it will take much time to starup NN next time as there are too many entries to merge with the fsimage. Also considering this situaion, NN is down due to power outage, it tried to restore / catch up the newest state during startup by merging fsimage and too many edit logs and user is expecting it is up ASAP~~~.
Why SNN / Checkpoint and how it works
I already pointed one of the reason above. Another reason is merging fs image with edit logs is expensive operation(I/O, CPU intensive) which may restrict the client accessing to the NN. So, we will use a seperate machine as Checkpoint node to hand over the load to. So, NN remains active all the time.
How it works?
The fsimage file name contains the transaction id. For example, fsimage_7, means this image file has all the transaction up to transaction id 7. Similarly, The current in-use edit log file is edits_in_progress_$tranID(edits_in_progress_21) which means transaction whose ID aboves 21 will be stored in this file. Old edit log file will be renamed to edits_8-20 and no write to it any more. So, what happens when checkpointing?
- CPN gets the known most recent transaction id from current in-use edit log which is 21.
- CPN gets the fs image transaction id which is 7.
- CPN will download the edit logs whose name is edit_8-20.
- CPN will check if it has the fs image file whose transaction is 7(it usually has).
- CPN will do the checkpointing by merging the fsimage_7 and edits_8-20, generating new fsimage_20.
- CPN will send the fsimage_20 to NN . so, both of them has the newly generated fsimage_20. Next time, CNP will not download it from NN.
When the checkpoint get triggered? according to official doc , either of the 2 meets will trigger checkpointing.
- dfs.namenode.checkpoint.period, set to 1 hour by default, specifies the maximum delay between two consecutive checkpoints, and
- dfs.namenode.checkpoint.txns, set to 1 million by default, defines the number of uncheckpointed transactions on the NameNode which will force an urgent checkpoint, even if the checkpoint period has not been reached.
Please note that, CPN does not keep in-memory metadata and does not have block locations which are from block reports sent by DNs.
Backup Node
See here . It looks to me that Backup Node is better than CPN.
node.js – node -bash:/usr/sbin / node:没有这样的文件或目录
我有这个错误,例如我运行此命令(在.js的目录中)
node sell.js
要么
screen node sell.js
它们都不起作用,因为我收到此错误:
-bash: /usr/sbin/node: No such file or directory
有人能帮助我吗?
解决方法
sudo ln -s /usr/bin/nodejs /usr/sbin / node
今天关于node.js - 求Md5withRsa php 、python、或者nodejs的实现,或者给讲讲原理?和nodejs md5解密的分享就到这里,希望大家有所收获,若想了解更多关于5、PHP-将浮点数转为整数 php 浮点数比较 php 浮点数精度 php 浮点数格式、elasticseatch 2.x Master-eligible node、Data node、Client node、Tribe node、HDFS essay 2 - Clarify Name Node / Checkpoint Node/ Backup Node、node.js – node -bash:/usr/sbin / node:没有这样的文件或目录等相关知识,可以在本站进行查询。
本文标签: