获取ubuntu键盘按键记录

简介

通常一台服务器都会开放权限给运维,开发等用户。随着服务器台数增长,用户交接/离职等,服务器的管理及安全也就成为一个重要的课题。如员工离职在服务器上留后门或恶意代码,这样的场景如何追踪该员工?
没错,可以借用键盘按键记录器。本文主要介绍如何通过logkeys来记录用户按键记录。

安装

sudo apt-get install logkeys

Continue reading

JAVA-电子签名范例代码

代码

import java.security.InvalidKeyException;
import java.security.Key;
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.Signature;
import java.security.SignatureException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * ECDSA 160bit 签名及签名验证例子
 */
public class ECDSASignature {

    public static void main(String argv[]) {
        signatureTest();
    }

    public static void signatureTest() {

        /**
         * 密钥对生成
         */
        KeyPairGenerator keyPairGenerator = null;
        try {
            keyPairGenerator = KeyPairGenerator.getInstance("EC");
        } catch (NoSuchAlgorithmException ex) {
            return;
        }
        SecureRandom secureRandom = new SecureRandom();
        keyPairGenerator.initialize(160, secureRandom);
        KeyPair pair = keyPairGenerator.generateKeyPair();
        Key publicKey = pair.getPublic();
        Key privateKey = pair.getPrivate();

        // 字符串
        String hako = "test";

        /**
         * 私钥签名(ECDSA 160bit)
         */
        byte[] sign = null;
        try {
            Signature signatureSign = null;
            signatureSign = Signature.getInstance("NONEwithECDSA");
            signatureSign.initSign((PrivateKey) privateKey, secureRandom);
            signatureSign.update(hako.getBytes());
            sign = signatureSign.sign();

            System.out.println("sign: " + new String(sign));

        } catch (InvalidKeyException | NoSuchAlgorithmException | SignatureException ex) {
            Logger.getLogger(ECDSASignature.class.getName()).log(Level.SEVERE, null, ex);
        }

        /**
         * 用公钥进行签名验证
         */
        Signature signatureVerify = null;
        try {
            signatureVerify = Signature.getInstance("NONEwithECDSA");
            signatureVerify.initVerify((PublicKey) publicKey);
            signatureVerify.update(hako.getBytes());
            boolean verifyResult = signatureVerify.verify(sign);
            System.out.println(verifyResult ? "签名OK" : "签名NG");

        } catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException e) {
            Logger.getLogger(ECDSASignature.class.getName()).log(Level.SEVERE, null, e);
        }

    }

}

运行结果

sign: *************
签名OK