找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 306|回复: 11

客户端登录签名获取源码,给需要自己做登录器的人

[复制链接]

772

主题

7427

回帖

2万

积分

登峰造极

积分
25333
发表于 2025-1-6 18:53:07 | 显示全部楼层 |阅读模式
RT
回复

使用道具 举报

772

主题

7427

回帖

2万

积分

登峰造极

积分
25333
 楼主| 发表于 2025-1-6 18:53:25 | 显示全部楼层
#include <openssl/rsa.h>
#include <openssl/pem.h>
#include <openssl/err.h>
#include <openssl/sha.h>
#include <openssl/hmac.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <string.h>
#include <stdlib.h>
#include <io.h>
void base64(const unsigned char *input,char *output, int length)
{
BIO *bmem, *b64;
BUF_MEM *bptr;
b64 = BIO_new(BIO_f_base64());
bmem = BIO_new(BIO_s_mem());
b64 = BIO_push(b64, bmem);
BIO_write(b64, input, length);
BIO_flush(b64);
BIO_get_mem_ptr(b64, &bptr);
memcpy(output, bptr->data, bptr->length-1);
output[bptr->length-1] = 0;
BIO_free_all(b64);
}
int private_key_sign(const unsigned char *input,int inputlen, const char *pri_key_fn, char *retstr)
{
RSA* p_rsa = NULL;
FILE* file = NULL;
char data[4096];
int nid;
unsigned int signlen;
int i = 0;
int ret = 0;
nid = NID_md5;
file = fopen(pri_key_fn, "rb");
if (!file)
{
ret = -1;
return ret;
}
if ((p_rsa = PEM_read_RSAPrivateKey(file, NULL, NULL, NULL)) == NULL)
{
ret = -2;
fclose(file);
return ret;
}
fclose(file);
ret = RSA_private_encrypt(inputlen, (const unsigned char*)input, (unsigned char *)data, p_rsa, RSA_PKCS1_PADDING);
if (ret < 1)
return -3;
signlen = ret;
char base64val[540];
base64((unsigned char *)data, base64val, signlen);
int len = strlen(base64val);
if(len<0 || len>539)
return -4;
int j=0;
for(int i=0;i<len;i++){
if(base64val == '\n')
continue;
retstr[j] = base64val;
j++;
}
retstr[j] = '\0';
RSA_free(p_rsa);
return 0;
}
extern int signUidToStartParam(int uid, const char *pem, char *dst)
{
unsigned char src[46] = {0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x55,0x91,0x45,0x10,0x01,0x04,0x03,0x03,0x01,0x01};
src[3] = uid & 0xFF;
src[2] = (uid >> 8) & 0xFF;
src[1] = (uid >> 16) & 0xFF;
src[0] = (uid >> 24) & 0xFF;
if (private_key_sign(src, 46, pem, dst))
return 0;
return 1;
}
int to_unsigned_number(const char *input){
int len = strlen(input);
if(len > 12)
return -1;
if(len == 0)
return -1;
int ret = 0;
for(int i=0;i<len;i++) {
ret = ret * 10;
if('0' > input || '9' < input)
return -1;
ret += input - '0';
}
return ret;
}
int main(int argc, char *argv[])
{
if(argc < 3){
printf("Usage: loginSign.exe [uid] [pem file]\n");
return 0;
}
int uid = to_unsigned_number(argv[1]);
char *pem = argv[2];
if(uid < 0) {
printf("Invalid UID!\n");
return 1;
}
if(access(pem, F_OK)) {
printf("File %s not exists!\n", pem);
return 1;
}
//公私钥生成命令:
//openssl genrsa -out privatekey.pem 2048
//openssl rsa -in privatekey.pem -pubout -out publickey.pem
char res[1024];
int isSuccess = signUidToStartParam(uid, pem, res); //参数1是用户的UID,参数2是私钥,参数3是返回值
if(isSuccess)
printf("%s\n", res);
else
return 1;
return 0;
}
回复

使用道具 举报

772

主题

7427

回帖

2万

积分

登峰造极

积分
25333
 楼主| 发表于 2025-1-6 18:53:52 | 显示全部楼层
完整源码在github上:similing4/login_sign
其实本质只有一个main.cpp,剩下的都是环境。主要用到了openssl1.1.1
回复

使用道具 举报

1309

主题

9862

回帖

3万

积分

管理员

积分
34974
发表于 2025-1-6 18:54:08 | 显示全部楼层
什么?龙王回来了?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

869

主题

7803

回帖

2万

积分

登峰造极

积分
26843
发表于 2025-1-6 18:54:57 | 显示全部楼层
看不懂,我只知道牛逼

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

869

主题

7803

回帖

2万

积分

登峰造极

积分
26843
发表于 2025-1-6 18:55:27 | 显示全部楼层


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

1431

主题

1万

回帖

3万

积分

登峰造极

积分
39303
发表于 2025-1-6 18:56:21 | 显示全部楼层
先保存 等看懂了在折腾
回复

使用道具 举报

1309

主题

9862

回帖

3万

积分

管理员

积分
34974
发表于 2025-1-6 18:57:12 | 显示全部楼层
插眼
回复

使用道具 举报

1309

主题

9862

回帖

3万

积分

管理员

积分
34974
发表于 2025-1-6 18:57:47 | 显示全部楼层
心语一拉就是坨大的!
回复

使用道具 举报

847

主题

7740

回帖

2万

积分

登峰造极

积分
26542
发表于 2025-1-6 18:58:04 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

772

主题

7427

回帖

2万

积分

登峰造极

积分
25333
 楼主| 发表于 2025-1-6 18:58:44 | 显示全部楼层
大佬,没放LICENSE啊,不敢用
回复

使用道具 举报

1453

主题

1万

回帖

3万

积分

登峰造极

积分
39286
发表于 2025-1-6 18:59:09 | 显示全部楼层
服务端加密的md5密码怎么生成的??我用openll生成md5,服务端解密不出来
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表