gpt4 book ai didi

angular - 如何解码 x509 证书以获取到期日期?

转载 作者:行者123 更新时间:2023-12-04 22:42:08 24 4
gpt4 key购买 nike

我正在开发一个项目,以从带有 angular/typescript 的 azure 集成帐户获取和显示证书信息。部分要求是将解码的公共(public)证书显示给用户以查找有用的信息,即到期日期。我一直在尝试使用 atob() 函数解码证书,但它没有正确解码证书。有没有一种简单的方法可以用 angular/typscript 做到这一点?
下面是一个证书的例子:

-----BEGIN CERTIFICATE-----
MIIDqDCCApCgAwIBAgICKg8wDQYJKoZIhvcNAQELBQAwWjELMAkGA1UEBhMCVVMx
EzARBgNVBAgTCldhc2hpbmd0b24xEDAOBgNVBAcTB1NlYXR0bGUxJDAiBgNVBAoT
G2dldGFDZXJ0IC0gd3d3LmdldGFjZXJ0LmNvbTAeFw0xOTExMDYwNjMwNDNaFw0y
MDAxMDUwNjMwNDNaMIGJMQswCQYDVQQGEwJBVTELMAkGA1UECBMCU0ExGjAYBgNV
BAcTEVJvc3RyZXZvciBTQSA1MDAwMRAwDgYDVQQKEwdDb3JzdGV4MRcwFQYDVQQD
Ew5BbGJlcnQgTWFyYXNoaTEmMCQGCSqGSIb3DQEJARYXYWxiZXJ0bWFzaHlAb3V0
bG9vay5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCdPRTB3j6k
XeylM4Tf7+s7YtjnGgc8Zseh4nX22xpo+sE+pYvOLu4NexprToJ64Yi/SMmBk9u2
0EkrvhWVkA1n8VyU6Oh57Oeg7cDMkqoabJ2CJBn/Z5AF3xrE9GYoymGsfHThd6nQ
JD/HRcErWGyAEwbnNG5CpwySVrMHo2A5va4pDwiDqQAf5rNLP0swtV7Q6UC6eJXs
I5Gbv3bhD8i44DLkj6rbY8uWClhns5XSG5R+rTwoYHkLolLPLj6Em7QtJKPyDsp1
6lzsjLsgzmRixFDhqI3HUlGUnAu6gwwxvP53qhSUi88sKe4M37med5HSAxv+U7A9
rr1js4ey84/9AgMBAAGjSDBGMAkGA1UdEwQCMAAwEQYJYIZIAYb4QgEBBAQDAgTw
MAsGA1UdDwQEAwIFIDAZBgNVHREEEjAQgg5BbGJlcnQgTWFyYXNoaTANBgkqhkiG
9w0BAQsFAAOCAQEAnXQAvyYE10bc5V9AsjT4x8xyI5AZ6su9OXEDuBFQi2UGvwtb
hhrBZ79Y3KfomXmwtHNVzo6V7dG+9yoDykaKb/Ub72VqF9ZKZArgglMFlGhAk90c
msxWGm7sHLBlt2yjkvnAtt1EtnbOtmuPNGOA7yALTN9/uzBPoTgkjuI1Fkb1uHc1
gynJpqrT0r/qJp0aDxO2SokWYzv/SRCfQTeLMZ5dctHWb8UnsEzt578zYmlDwVof
tOniZVO5TwnXCaWOPjG9XKbW6wHUyMWbulxM9SJUeIjFI2ipQuW8O7Vd94aEyH8o
lc8zFSWoNxamcoX+4ajrs9VbNXythJ91UAtvtA==
-----END CERTIFICATE-----
以下是一些代码供引用:
服务
@Injectable()
export class integrationAccountService
{
constructor(private httpclient: HttpClient, private api: ApiService) { }

getcertificates(): Observable<Certificate> {
const httpOptions : Object = {
headers: new HttpHeaders({
'Authorization': 'Bearer Token'
}),
responseType: 'json'
};
return this.httpclient.get<Certificate>(URL, httpOptions);
}
}
表组件
export class CertificateTableComponent {

dataSource: MatTableDataSource<any>;
//certificates: ValueEntity[] = [];
data: CertificateRow[] = [];
columns: string[] = ['name', 'id', 'type', 'publicCertificate'];

@ViewChild(MatSort, { static: true }) sort: MatSort;
@ViewChild(MatPaginator, { static:true }) paginator: MatPaginator;

constructor(private _integrationAccountService: integrationAccountService, public dialog: MatDialog) {
}

ngOnInit() {

this._integrationAccountService.getcertificates().subscribe(response => {
//this.certificates = response.data;
this.data = [];
if (response.value) {
for (let entity of response.value) {
let row: CertificateRow = {
name: entity.name,
id: entity.id,
type: entity.type,
publicCertificate: entity.properties?.publicCertificate
};
this.data.push(row);
console.log(atob(row.publicCertificate));
}
}

this.dataSource = new MatTableDataSource(this.data);
this.dataSource.sort = this.sort;
this.dataSource.paginator = this.paginator;

})

}
applyFilter(event) {
const filterValue = (event.target as HTMLInputElement).value;

this.dataSource.filter = filterValue.trim().toLowerCase()
}

openDialog(publicCertificate) {
let dialogRef = this.dialog.open(CertificateViewComponent, {
data: {
dialogCert: publicCertificate
}

});
}
}
有了这个 console.log(atob(row.certificate));不会产生解码的证书,它只显示从 api 返回的证书。我在这里缺少什么或其他方法来解码证书吗?
提前致谢!

最佳答案

我找到了使用 node-forge 包的解决方案。这是我在表格组件中实现的代码:

import * as forge from 'node-forge';

declare var require: any
const pki = require('node-forge').pki;

const certPem = atob(entity.properties?.publicCertificate)
const cert = pki.certificateFromPem(certPem)

console.log(cert);

关于angular - 如何解码 x509 证书以获取到期日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68009632/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com