Skip to content

Commit beb1c53

Browse files
committed
SPM change to GMObjC.xcframework
1 parent 83483e9 commit beb1c53

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2013
-4
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>AvailableLibraries</key>
6+
<array>
7+
<dict>
8+
<key>BinaryPath</key>
9+
<string>GMObjC.framework/GMObjC</string>
10+
<key>DebugSymbolsPath</key>
11+
<string>dSYMs</string>
12+
<key>LibraryIdentifier</key>
13+
<string>ios-arm64</string>
14+
<key>LibraryPath</key>
15+
<string>GMObjC.framework</string>
16+
<key>SupportedArchitectures</key>
17+
<array>
18+
<string>arm64</string>
19+
</array>
20+
<key>SupportedPlatform</key>
21+
<string>ios</string>
22+
</dict>
23+
<dict>
24+
<key>BinaryPath</key>
25+
<string>GMObjC.framework/Versions/A/GMObjC</string>
26+
<key>DebugSymbolsPath</key>
27+
<string>dSYMs</string>
28+
<key>LibraryIdentifier</key>
29+
<string>macos-arm64_x86_64</string>
30+
<key>LibraryPath</key>
31+
<string>GMObjC.framework</string>
32+
<key>SupportedArchitectures</key>
33+
<array>
34+
<string>arm64</string>
35+
<string>x86_64</string>
36+
</array>
37+
<key>SupportedPlatform</key>
38+
<string>macos</string>
39+
</dict>
40+
<dict>
41+
<key>BinaryPath</key>
42+
<string>GMObjC.framework/GMObjC</string>
43+
<key>DebugSymbolsPath</key>
44+
<string>dSYMs</string>
45+
<key>LibraryIdentifier</key>
46+
<string>ios-arm64_x86_64-simulator</string>
47+
<key>LibraryPath</key>
48+
<string>GMObjC.framework</string>
49+
<key>SupportedArchitectures</key>
50+
<array>
51+
<string>arm64</string>
52+
<string>x86_64</string>
53+
</array>
54+
<key>SupportedPlatform</key>
55+
<string>ios</string>
56+
<key>SupportedPlatformVariant</key>
57+
<string>simulator</string>
58+
</dict>
59+
</array>
60+
<key>CFBundlePackageType</key>
61+
<string>XFWK</string>
62+
<key>XCFrameworkFormatVersion</key>
63+
<string>1.0</string>
64+
</dict>
65+
</plist>
Binary file not shown.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Created by lifei on 2023/9/14.
2+
// 参考 issue 反馈,总结遇到的问题,协助分析;
3+
// 用于测试环境排查故障,不能用于生产环境。
4+
5+
#import <Foundation/Foundation.h>
6+
7+
NS_ASSUME_NONNULL_BEGIN
8+
9+
@interface GMDoctor : NSObject
10+
#ifdef DEBUG
11+
12+
// 检查 SM2 加密
13+
+ (void)checkSm2Encrypt:(NSData *)plainData publicKey:(NSString *)publicKey;
14+
// 检查 SM2 解密
15+
+ (void)checkSm2Decrypt:(NSData *)cipherData privateKey:(NSString *)privateKey;
16+
// 检查 SM2 签名
17+
+ (void)checkSignData:(NSData *)plainData privateKey:(NSString *)privateKey userData:(nullable NSData *)userData;
18+
// 检查 SM2 验签
19+
+ (void)checkVerifyData:(NSData *)plainData signRS:(NSString *)signRS publicKey:(NSString *)publicKey userData:(nullable NSData *)userData;
20+
// 检查 SM2 公钥
21+
+ (void)checkSm2PublicKey:(NSString *)publicKey;
22+
// 检查 SM2 私钥
23+
+ (void)checkSm2PrivateKey:(NSString *)privateKey;
24+
// 检查 OpenSSL 环境
25+
+ (void)checkEnvironment;
26+
27+
#endif
28+
@end
29+
30+
NS_ASSUME_NONNULL_END
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Created by lifei on 2019/8/2.
2+
// Copyright © 2019 lifei. All rights reserved.
3+
/**
4+
* 基于 OpenSSL 对国密 SM2 非对称加密、SM2 签名验签、ECDH 密钥协商、SM3 摘要算法,SM4 对称加密做 OC 封装。
5+
* GMSm2Utils SM2 非对称加解密及签名验签,ECDH密钥协商
6+
* GMSm2Bio PEM/DER 格式公私钥读取或创建
7+
* GMSm3Utils SM3 摘要提取,HMAC 计算
8+
* GMSm4Utils SM4 对称加解密,含ECB和CBC模式
9+
* GMSmUtils 工具类,16进制编码解码等
10+
* GMDoctor 问题诊断,仅用于 Debug 环境调试检查可能遇到的问题
11+
*/
12+
13+
#import <Foundation/Foundation.h>
14+
15+
#define GMOBJC_VERSION_NUMBER 0x400000
16+
#define GMOBJC_VERSION_TEXT "GMObjC 4.0.0 08 Nov 2024"
17+
18+
#if __has_include(<GMObjC/GMSm2Bio.h>)
19+
#import <GMObjC/GMSm2Bio.h>
20+
#import <GMObjC/GMSm2Utils.h>
21+
#import <GMObjC/GMSm3Utils.h>
22+
#import <GMObjC/GMSm4Utils.h>
23+
#import <GMObjC/GMSmUtils.h>
24+
#import <GMObjC/GMDoctor.h>
25+
#else
26+
#import "GMSm2Bio.h"
27+
#import "GMSm2Utils.h"
28+
#import "GMSm3Utils.h"
29+
#import "GMSm4Utils.h"
30+
#import "GMSmUtils.h"
31+
#import "GMDoctor.h"
32+
#endif
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
//
2+
// GMSm2Bio.h
3+
// GMObjC_Example
4+
//
5+
// Created by lifei on 2021/4/24.
6+
// Copyright © 2021 lifei. All rights reserved.
7+
/**
8+
* SM2 密钥类文件 IO 操作,PEM/DER/CER/PKCS#12 等格式公私钥读取或创建
9+
*/
10+
11+
#import <Foundation/Foundation.h>
12+
13+
NS_ASSUME_NONNULL_BEGIN
14+
15+
// 读取的证书信息
16+
@interface GMSm2X509Info : NSObject
17+
18+
@property (nullable, nonatomic, copy) NSString *version; // 证书的版本号
19+
@property (nullable, nonatomic, copy) NSString *publicKey; // 公钥(HEX 格式)
20+
@property (nullable, nonatomic, copy) NSString *privateKey; // 私钥(HEX 格式,PKCS#12格式可能包含)
21+
@property (nullable, nonatomic, copy) NSString *effectiveDate; // 生效日期,日期格式(UTC时间) yyyyMMddHHmmss
22+
@property (nullable, nonatomic, copy) NSString *expirationDate; // 失效日期,日期格式(UTC时间) yyyyMMddHHmmss
23+
@property (nullable, nonatomic, copy) NSString *serialNumber; // 证书的序列号
24+
@property (nullable, nonatomic, copy) NSString *signature; // 签名算法的值
25+
@property (nullable, nonatomic, copy) NSString *signatureAlgorithm; // 签名算法类型
26+
@property (nullable, nonatomic, copy) NSString *sha1Fingerprint; // 指纹(SHA-1)
27+
@property (nullable, nonatomic, copy) NSString *sha256Fingerprint; // 指纹(SHA-256)
28+
29+
@property (nullable, nonatomic, copy) NSString *country; // 证书的国家代码
30+
@property (nullable, nonatomic, copy) NSString *commonName; // 证书的通用名称
31+
@property (nullable, nonatomic, copy) NSString *organization; // 证书的组织名称
32+
@property (nullable, nonatomic, copy) NSString *organizationalUnit; // 证书的组织单位名称
33+
34+
@property (nullable, nonatomic, copy) NSString *issuerCountry; // 颁发机构的国家代码
35+
@property (nullable, nonatomic, copy) NSString *issuerCommonName; // 颁发机构的通用名称
36+
@property (nullable, nonatomic, copy) NSString *issuerOrganization; // 颁发机构的组织名称
37+
@property (nullable, nonatomic, copy) NSString *issuerOrganizationalUnit; // 颁发机构的组织单位名称
38+
39+
@end
40+
41+
// 生成的PEM/DER格式公私钥文件路径
42+
@interface GMSm2KeyFiles : NSObject
43+
44+
@property (nullable, nonatomic, copy) NSString *publicKeyPath;
45+
@property (nullable, nonatomic, copy) NSString *privateKeyPath;
46+
47+
@end
48+
49+
@interface GMSm2Bio : NSObject
50+
51+
// MARK: - 读取PEM格式秘钥
52+
/// 从 PEM 文件中读取 SM2 公钥,返回 HEX 格式公钥
53+
/// @param pemData PEM 格式公钥数据
54+
/// @param pwdData PEM 格式证书密码,无密码时传入 nil
55+
+ (nullable NSString *)readPublicKeyFromPemData:(NSData *)pemData password:(nullable NSData *)pwdData;
56+
57+
/// 从 PEM 文件中读取 SM2 私钥,返回 HEX 格式私钥
58+
/// @param pemData PEM 格式私钥数据
59+
/// @param pwdData PEM 格式证书密码,无密码时传入 nil
60+
+ (nullable NSString *)readPrivateKeyFromPemData:(NSData *)pemData password:(nullable NSData *)pwdData;
61+
62+
// MARK: - 读取DER格式秘钥
63+
/// 从 DER 文件中读取 SM2 公钥,返回 HEX 格式公钥
64+
/// @param derData DER 格式公钥数据
65+
+ (nullable NSString *)readPublicKeyFromDerData:(NSData *)derData;
66+
67+
/// 从 DER 文件中读取 SM2 私钥,返回 HEX 格式私钥
68+
/// @param derData DER 格式私钥数据
69+
+ (nullable NSString *)readPrivateKeyFromDerData:(NSData *)derData;
70+
71+
// MARK: - 写入PEM/DER格式文件
72+
/// 将公钥/私钥写入PEM文件,返回YES成功,NO失败
73+
/// @param publicHex 04 开头的公钥,privateHex 私钥( 皆为HEX 编码格式)
74+
/// @param filePath PEM文件存储路径
75+
+ (BOOL)savePublicKey:(NSString *)publicHex toPemFileAtPath:(NSString *)filePath;
76+
+ (BOOL)savePrivateKey:(NSString *)privateHex toPemFileAtPath:(NSString *)filePath;
77+
78+
/// 将公钥/私钥写入DER文件,返回YES成功,NO失败
79+
/// @param publicHex 04 开头的公钥,privateHex 私钥( 皆为HEX 编码格式)
80+
/// @param filePath DER文件存储路径
81+
+ (BOOL)savePublicKey:(NSString *)publicHex toDerFileAtPath:(NSString *)filePath;
82+
+ (BOOL)savePrivateKey:(NSString *)privateHex toDerFileAtPath:(NSString *)filePath;
83+
84+
// MARK: - PEM & DER 字符互转
85+
/// 将 PEM 格式公私钥转换为 DER 格式
86+
/// @param pemData PEM格式密钥数据
87+
/// @param isPublicKey 标记 derData 是公钥/私钥,YES为公钥,NO为私钥
88+
+ (nullable NSData *)convertPemToDer:(NSData *)pemData isPublicKey:(BOOL)isPublicKey;
89+
90+
/// 将 DER 格式公私钥转换为 PEM 格式
91+
/// @param derData DER格式密钥数据
92+
/// @param isPublicKey 标记 derData 是公钥/私钥,YES为公钥,NO为私钥
93+
+ (nullable NSData *)convertDerToPem:(NSData *)derData isPublicKey:(BOOL)isPublicKey;
94+
95+
// MARK: - 读取证书
96+
/// 从证书文件中读取证书信息,读取的公私钥可能非 SM2 密钥信息(可能是 RSA)
97+
/// @param cerData 证书文件数据
98+
/// @param pwdData 证书密码,默认为空
99+
+ (nullable GMSm2X509Info *)readX509InfoFromData:(NSData *)cerData password:(nullable NSData *)pwdData;
100+
101+
// MARK: - 创建PEM/DER格式公私钥
102+
/// 创建 PEM 格式 SM2 公私钥,默认保存tmp文件夹下。
103+
/// 返回值:数组元素 1 为公钥sm2-pub.pem/.der路径,2 为私钥sm2-pri.pem/.der路径
104+
+ (GMSm2KeyFiles *)generatePemKeyFiles;
105+
+ (GMSm2KeyFiles *)generateDerKeyFiles;
106+
107+
@end
108+
109+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)