2013年5月

openssl genkey 和 ssk-keygen 密钥的格式是不一样的
“RFC4716” (RFC 4716/SSH2 public or private key)
“PKCS8” (PEM PKCS8 public key)
ubuntu:
ssh-keygen -e -f ~/.ssh/id_rsa.pub > ~/.ssh/id_rsa_pub.pem
ssh-keygen -f ~/.ssh/id_rsa_pub.pem -i -m RFC4716 > ~/.ssh/id_rsa.pub
windows:
1)Use the puttyGen
2) Run puttygen and click generate
3) Run your mouse round the blank part for a while.
4) Enter a keyphrase (and repeat)
5) Click save public key and save it publickey
6) Click save private key and save it privatekey (extension gets added automatically, this is no good for spoon, but good for putty)
7) Click Conversions->Export OpenSSH key and save as sshkey.pem
8) In the main window is you key for pasting into OpenSSH authorized_keys file. Copy this in its entirety and past it into your ubuntu machine in /home//.ssh/authorized_keys file.
9) Ok, you can close putty key generator.
10) Utilize the .pem in the tool.
http://www.yinqisen.cn/blog-177.html

#include 
#include 
#include 
#include 
#include 
int main(int argc, char **argv)
{
    MD5_CTX ctx;
    unsigned char md[32 + 1];
    char    md5[32 + 1];
    char    tmp[2];
    char    buff[256];
    char    *filename;
    FILE    *fp;
    int     i;
    if (argc < 2) {
        printf("Usage:%s n", argv[0]);
        exit(1);
    }
    filename = argv[1];
    memset(md5, 0x00, sizeof(md5));
    memset(md, 0x00, sizeof(md));
    if(MD5_Init(&ctx) == 0) {
        perror("MD5_Init");
        exit(1);
    }
    if((fp=fopen(filename,"rb")) == NULL) {
        perror("fopen");
        exit(1);
    }
    while (! feof(fp) ) {
        memset(buff, 0x00, sizeof(buff));
        fgets(buff, 256, fp);
        if(MD5_Update(&ctx, buff, strlen(buff)) == 0) {
            perror("MD5_Update");
            exit(1);
        }
    }
    fclose(fp);
    if(MD5_Final(md, &ctx) == 0) {
        perror("MD5_Final:");
        exit(1);
    }
        for(i=0; i< 16; i++) {
        memset(tmp, 0x00, sizeof(tmp));
            sprintf(tmp, "%02X", md[i]);
            strcat(md5, tmp);
    }
    printf("md5(%s):%sn", filename, md5);
    return 0;
}
root@bt:~/c# cc -o testmd5 testmd5.c -lssl
root@bt:~/c# ./testmd5 1.c
md5(1.c):1558734758F8CB08D6DB8D5B57E71BF7
root@bt:~/c# ./testmd5 2.c
md5(2.c):0C8E614EC0AB5B5CEF90D012F5C11797
root@bt:~/c# openssl md5 1.c
MD5(1.c)= 1558734758f8cb08d6db8d5b57e71bf7
root@bt:~/c# openssl md5 2.c
MD5(2.c)= 0c