BBASMPMSSignChecker.h 1.53 KB
//
//  BBASMPMSSignChecker.h
//  BBAMNP
//
//  Created by baidu on 2019/3/19.
//  Copyright © 2019 Baidu. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/**
 * PMS package signature checker.
 */
@interface BBASMPMSSignChecker : NSObject

/**
 * @brief Get MD5 value from signature using RSA decrypt.
 *
 * @param sign Package signature.
 * @return MD5 value.
 */
+ (NSString *)md5WithSign:(NSString *)sign;

/**
 * @brief Verify the file with a given MD5 value.
 *
 * @param md5 A given MD5 value.
 * @param filePath The downloaded file path.
 * @return Whether the file is valid.
 */
+ (BOOL)verifyMD5:(NSString *)md5
        aboutFile:(NSString *)filePath;


/**
 * @brief Verify the file with the signature.
 *
 * @param sign signature from pms server.
 * @param filePath The downloaded file path.
 * @return Whether the file is valid.
 */
+ (BOOL)verifySign:(NSString *)sign
         aboutFile:(NSString *)filePath;

/**
 * @brief Verify the file with the signature.
 *
 * @param sign signature from pms server.
 * @param MD5 A given MD5 value.
 * @return Whether the MD5 is valid.
 */
+ (BOOL)verifySign:(NSString *)sign
           withMD5:(NSString *)MD5;


#pragma mark - Dynamic MD5 digest

/**
 * @brief CC_MD5_Init, initialize md5 context.
 */
- (void)md5Init;

/**
 * @brief CC_MD5_Update, update data for md5 context.
 */
- (void)md5UpdateWithData:(NSData *)data;

/**
 * @brief CC_MD5_Final, get final md5 value.
 *
 * @return Fianl md5 value of the whole data.
 */
- (NSString *)md5Final;
@end

NS_ASSUME_NONNULL_END