小编Joe*_*son的帖子

Python 密码学:创建由现有 CA 签名的证书,并导出

我正在创建一个像这样的 CA:

openssl genrsa -out ca.key 4096
openssl req -new -x509 -days 3650 -key ca.key -out ca.cert
Run Code Online (Sandbox Code Playgroud)

这给了我两个 PEM 文件。

然后我调用这个函数,其中cert_authorityprivate_key是上面生成的数据的字符串。

def create_cert(cert_authority, private_key):
    one_day = datetime.timedelta(1, 0, 0)
    # Use our private key to generate a public key
    private_key = serialization.load_pem_private_key(
        private_key.encode("ascii"), password=None, backend=default_backend()
    )
    public_key = private_key.public_key()

    ca = x509.load_pem_x509_certificate(
        cert_authority.encode("ascii"), default_backend()
    )

    builder = x509.CertificateBuilder()
    builder = builder.subject_name(
        x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, u"cryptography.io")])
    )
    builder = builder.issuer_name(ca.issuer)
    builder = builder.not_valid_before(datetime.datetime.today() - one_day)
    builder = builder.not_valid_after(datetime.datetime.today() + …
Run Code Online (Sandbox Code Playgroud)

python cryptography python-3.x

8
推荐指数
2
解决办法
5689
查看次数

PowerShell:选择匹配前的行 - 使用输入字符串变量时的Select-String -Context问题

我需要在多行字符串变量的匹配之前返回一行.

当输入使用字符串变量时,Select-String似乎认为整个字符串已匹配.因此,Context属性在字符串的两端"外部"并且为null.

考虑以下示例:

$teststring = @"
line1
line2
line3
line4
line5
"@

Write-Host "Line Count:" ($teststring | Measure-Object -Line).Lines #verify PowerShell does regard input as a multi-line string (it does)

Select-String -Pattern "line3" -InputObject $teststring -AllMatches -Context 1,0 | % {
$_.Matches.Value #this prints the exact match
$_.Context #output shows all context properties to be empty 
$_.Context.PreContext[0] #this would ideally output first line before the match
$_.Context.PreContext[0] -eq $null #but instead is null
}
Run Code Online (Sandbox Code Playgroud)

我在这里误解了什么吗?

匹配"line3"时返回"line2"的最佳方法是什么?

谢谢!

编辑:我忽略的附加要求:需要在所有匹配的行上方提供一行不确定长度的行.EG在下面搜索"line3"时我需要返回"line2"和"line5".

line1
line2 …
Run Code Online (Sandbox Code Playgroud)

string powershell match select-string

4
推荐指数
1
解决办法
5446
查看次数

将Storyboard中的UINavigationController链接到AppDelegate

所以我开始使用单一视图模板的iOS应用程序.然后我通过将导航控制器拖入故事板来添加导航控制器.如何从我的应用代表中引用它?我试着将它拖动到我的AppDelegate插座风格中,但这显然不起作用.我该怎么办?实例化一个,然后将其分配为rootview控制器?

到此为止,我想使用AppDelegate将视图设置为导航控制器的顶部.谢谢!

cocoa-touch objective-c appdelegate

1
推荐指数
1
解决办法
3550
查看次数