洛阳学员端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.2 KiB

9 months ago
  1. //
  2. // BioAuthCryptoManager.hpp
  3. // BioAuthEngine
  4. //
  5. // Created by yukun.tyk on 5/16/16.
  6. // Copyright © 2016 DTF. All rights reserved.
  7. //
  8. #ifndef BioAuthCryptoManager_hpp
  9. #define BioAuthCryptoManager_hpp
  10. #import <Foundation/Foundation.h>
  11. #include <stdio.h>
  12. #import <functional>
  13. #import <Foundation/NSData.h>
  14. #import <Foundation/NSString.h>
  15. namespace DTF {
  16. /**
  17. *
  18. *
  19. * @param success:
  20. * @param cipher:
  21. * @param encryptedKey: RSA公钥加密的AES密钥
  22. */
  23. typedef std::function<void(bool, NSData *, NSData *)> completionCallback;
  24. class ToygerCryptoManager{
  25. public:
  26. /**
  27. * 1. 128AES私钥
  28. * 2. ASE私钥加密业务数据
  29. * 3. RSA公钥加密AES密钥
  30. *
  31. * @param content
  32. * @param pubKey RSA公钥
  33. * @param callback callback
  34. */
  35. static void mixEncrypt(NSData *content, NSString *pubKey, completionCallback callback);
  36. /**
  37. * AES加密
  38. *
  39. * @param content
  40. * @param aesKey AES密钥
  41. *
  42. * @return Nil
  43. */
  44. static NSData *AESEncrypt(NSData *content, NSString *aesKey ,NSUInteger value=0);
  45. //获取md5值
  46. static NSString *MD5WithData(NSData *data);
  47. /**
  48. * AES解密
  49. *
  50. * @param content
  51. * @param aesKey AES密钥
  52. *
  53. * @return Nil
  54. */
  55. static NSData *AESDecrypt(NSData *content, NSString *aesKey);
  56. /**
  57. * 1024RSA加密
  58. *
  59. * @param content 128
  60. * @param pubKey RSA公钥
  61. *
  62. * @return nil
  63. */
  64. static NSData *RSAEncrypt(NSData *content, NSString *pubKey);
  65. /**
  66. *
  67. *
  68. * @param content
  69. * @param signature
  70. * @param pubKey RSA公钥
  71. *
  72. * @return
  73. */
  74. static BOOL checkSign(NSData *content, NSData *signature, NSString *pubKey);
  75. /**
  76. * MD5
  77. *
  78. * @param str
  79. *
  80. * @return MD5值
  81. */
  82. static NSString *calculateMD5(NSString *str);
  83. /**
  84. * UUID
  85. */
  86. static NSString *generateUUID();
  87. // /**
  88. // * RC4编码
  89. // */
  90. // static NSData *RC4Crypt(NSData *data, int code);
  91. // private:
  92. /**
  93. *
  94. *
  95. * @param len 32
  96. *
  97. * @return
  98. */
  99. static NSString *generateToken(NSInteger len);
  100. private:
  101. static NSData *stripPublicKeyHeader(NSData *pubKey);
  102. static SecKeyRef addPublicKey(NSString *pubKey);
  103. };
  104. }
  105. #endif /* BioAuthCryptoManager_hpp */