Crypto.ts 1.46 KB
// @ts-ignore
import type { ICrypto, Mode, Pad, ENC, OnErrorCallback, ICryptoSymmetric, WordArray} from '../utssdk/interface'
// import CryptoJS from 'crypto-es';
import CryptoJS from './lib';
import { RSAHandler } from './rsa';
// import { ICryptoFailImpl } from '../utssdk/unierror'

export class CryptoImpl implements ICrypto {
	private rsaHandler: RSAHandler;
	constructor() { 
		this.rsaHandler = new RSAHandler();
	}
	// @ts-ignore
	get enc() {
		return CryptoJS.enc //as ENC
	}
	// @ts-ignore
	get mode() {
		return CryptoJS.mode // as Mode
	}
	// @ts-ignore
	get pad() {
		return CryptoJS.pad // as Pad
	}
	// @ts-ignore
	get AES() {
		return CryptoJS.AES// as ICryptoAES
	}
	// @ts-ignore
	get DES() {
		return CryptoJS.DES// as ICryptoDES
	}
	get RSA() {
		 return this.rsaHandler;
	}
	// @ts-ignore
	MD5(message : string){
		return CryptoJS.MD5(message)//.toString()
	}
	// @ts-ignore
	SHA1(message : string) {
		return CryptoJS.SHA1(message)//.toString()
	}
	// @ts-ignore
	SHA256(message : string)  {
		return CryptoJS.SHA256(message)//.toString()
	}
	// @ts-ignore
	SHA512(message : string) {
		return CryptoJS.SHA512(message)//.toString()
	}
	// @ts-ignore
	HmacSHA256(message: string, secretKey: string|WordArray) {
		return CryptoJS.HmacSHA256(message, secretKey)//.toString()
	}
	// @ts-ignore
	HmacSHA1(message : string, secretKey : string|WordArray) {
		return CryptoJS.HmacSHA1(message, secretKey)//.toString()
	}
	onError(callback: OnErrorCallback) {
		// ICryptoFailImpl
	}
}