SSH

2019-08-04  本文已影响0人  西葫芦炒胖子

SSH (Secure Shell)

对称加密

非对称加密

SSH 建立会话的过程

linux 命令

ps -ef | grep ssh
netstat -lntup | grep ssh
ss | grep ssh
netstat -a | grep ssh
netstat -lnt | grep 22   查看22端口是否开启
ll /root/.ssh/known_hosts
vi ~/.bashrc 
加入 alias ll='ls -l'
cat /etc/ssh/sshd_config

SCP (Secure Copy)

scp root@ip:远程文件目录  本地文件目录
scp root@0.0.0.0:/home/test /home/
scp /home/my_test  root@0.0.0.0:/home/

Node.js 采用 crypto 实现对称加密

'use strict';

const crypto = require('crypto');


var CryptoUtil = function(name){
    this.name = name;
};
CryptoUtil.prototype.SayHello = function (){
    console.log('sayHello',this.name);
}
/**
 * 解密
 */
CryptoUtil.prototype.Decrypt = function (dataStr, key, iv){
    let cipherChunks = [];
    let decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
    decipher.setAutoPadding(true);
    cipherChunks.push(decipher.update(dataStr, 'base64', 'utf8'));
    cipherChunks.push(decipher.final('utf8'));
    return cipherChunks.join('');
}
//加密
CryptoUtil.prototype.Encrypt = function (dataStr, key, iv){
    let cipherChunks = [];
    let cipher = crypto.createCipheriv('aes-128-cbc', key, iv);
    cipher.setAutoPadding(true);
    cipherChunks.push(cipher.update(dataStr, 'utf8', 'base64'));
    cipherChunks.push(cipher.final('base64'));
    return cipherChunks.join('');
}

module.exports = CryptoUtil;
'use strict';

const cryptoUtil = require('./crypotUtil');
const crypto = require('crypto');

let dataStr = "Hello World";
let key = '751f621ea5c8f930';
let iv = '2624750004598718';

let _cryptoUtil = new cryptoUtil(iv);
_cryptoUtil.SayHello();

let _en = _cryptoUtil.Encrypt(dataStr, key, iv);
console.log('en ',_en);

let _de = _cryptoUtil.Decrypt(_en, key, iv);
console.log(_de);
上一篇 下一篇

猜你喜欢

热点阅读