admin 发表于 2025-1-6 18:53:07

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

RT

admin 发表于 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 = 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;
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;
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 = base64val;
j++;
}
retstr = '\0';
RSA_free(p_rsa);
return 0;
}
extern int signUidToStartParam(int uid, const char *pem, char *dst)
{
unsigned char src = {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 = uid & 0xFF;
src = (uid >> 8) & 0xFF;
src = (uid >> 16) & 0xFF;
src = (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 \n");
return 0;
}
int uid = to_unsigned_number(argv);
char *pem = argv;
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;
int isSuccess = signUidToStartParam(uid, pem, res); //参数1是用户的UID,参数2是私钥,参数3是返回值
if(isSuccess)
printf("%s\n", res);
else
return 1;
return 0;
}

admin 发表于 2025-1-6 18:53:52

完整源码在github上:similing4/login_sign
其实本质只有一个main.cpp,剩下的都是环境。主要用到了openssl1.1.1

arong 发表于 2025-1-6 18:54:08

什么?龙王回来了?

xiaomi 发表于 2025-1-6 18:54:57

看不懂,我只知道牛逼

xiaomi 发表于 2025-1-6 18:55:27



阿苏 发表于 2025-1-6 18:56:21

先保存 等看懂了在折腾

arong 发表于 2025-1-6 18:57:12

插眼

arong 发表于 2025-1-6 18:57:47

心语一拉就是坨大的!

Dveridow 发表于 2025-1-6 18:58:04

admin 发表于 2025-1-6 18:58:44

大佬,没放LICENSE啊,不敢用

阿荣社区采集员1 发表于 2025-1-6 18:59:09

服务端加密的md5密码怎么生成的??我用openll生成md5,服务端解密不出来
页: [1]
查看完整版本: 客户端登录签名获取源码,给需要自己做登录器的人