我有以下内容:
-----BEGIN CERTIFICATE-----
MIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCB
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
MIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCBMIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCBMIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCB
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
AgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCBMIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCB
-----END CERTIFICATE-----
我希望在----- BEGIN CERTIFICATE -----和----- END CERTIFICATE -----之间获取所有三个字符串,然后将它们存储在python中的变量中。我怎么在python中做到这一点?
答案 0 :(得分:1)
如果证书存储在一个字符串中,您可以这样做:
start_flag = "-----BEGIN CERTIFICATE-----"
end_flag = "-----END CERTIFICATE-----"
keys = []
for CERTIFICATE in CERTIFICATES.split( end_flag ):
key = CERTIFICATE.lstrip( start_flag )
keys.append( key )
print keys