Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GMSm2Utils 加密后返回空字符串 #90

Open
stoneioslife opened this issue Mar 22, 2024 · 1 comment
Open

GMSm2Utils 加密后返回空字符串 #90

stoneioslife opened this issue Mar 22, 2024 · 1 comment

Comments

@stoneioslife
Copy link

环境:GMObjC 3.3.0 Xcode15.2 iOS17.2模拟器

问题:
截屏2024-03-22 10 21 35

返回sm2Pwd为nil。

步骤:1.将用户输入密码进行 MD5|
方法如下:

  • (NSString *)getMd5_32Bit:(NSString *)pwd
    {
    const char *cStr = [pwd UTF8String];
    unsigned char digest[CC_MD5_DIGEST_LENGTH];
    CGFloat pwdLength = pwd.length;
    CC_MD5( cStr, pwdLength, digest );
    NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
    [result appendFormat:@"%02x", digest[i]];
    return result;
    }

2.将 MD5 的字符串进行 GMSm2Utils encryptText 加密。使用后台返回的公钥。
也使用过encryptHex方法,也是同样返回 nil

@muzipiao
Copy link
Owner

muzipiao commented Apr 3, 2024

oldPwd 可以是任意字符串,返回为空,原因可能如下:

  1. 很可能是项目中的 OpenSSL 版本较旧,不支持 SM2;
  2. 公钥不正确,非04开头的 HEX 格式密钥,默认椭圆曲线为 NID_sm2,如果后端不是,客户端需要通过 setEllipticCurveType 设置椭圆曲线。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants