-
Notifications
You must be signed in to change notification settings - Fork 89
/
exportBase64.ts
29 lines (24 loc) · 991 Bytes
/
exportBase64.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { _afterPluginsLoaded } from '../../helpers/_afterPluginsLoaded';
import { _extractMeaningfulErrorMessage } from '../../helpers/_extractMeaningfulErrorMessage';
import { __cadesAsyncToken__, _generateCadesFn } from '../../helpers/_generateCadesFn';
import { Certificate } from './certificate';
/**
* Экспортирует сертификат в формате base64
*
* @returns сертификат в формате base64
*/
export const exportBase64 = _afterPluginsLoaded(function (): string {
const cadesCertificate = (this as Certificate)._cadesCertificate;
return eval(
_generateCadesFn(function exportBase64(): string {
let base64: string;
try {
base64 = __cadesAsyncToken__ + cadesCertificate.Export(0);
} catch (error) {
console.error(error);
throw new Error(_extractMeaningfulErrorMessage(error) || 'Ошибка при экспорте сертификата');
}
return base64;
}),
);
});