下面的PowerShell命令创建一个自签名证书,其中SHA1作为签名算法.
New-SelfSignedCertificate -DnsName "MyCertificate", "www.contoso.com" -CertStoreLocation "cert:\LocalMachine\My" -Provider "Microsoft Strong Cryptographic Provider"
Run Code Online (Sandbox Code Playgroud)
是否有任何值可以传递给此命令(例如-KeyAlgorithm
:)以使用SHA256生成证书作为签名算法?
我想抑制这些警告,但我无法弄清楚如何做到这一点.
我正在使用创建Web API Express
.该功能允许API用户将文件发送到服务器.
这是我的应用设置代码:
var express = require('express');
var path = require('path');
// ...
var bodyParser = require('body-parser');
var routes = require('./routes/index');
var users = require('./routes/users');
// API routes
var images = require('./routes/api/img');
var app = express();
app.use(bodyParser.raw());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.use('/api', images);
// ...
module.exports = app;
Run Code Online (Sandbox Code Playgroud)
请注意我正在使用app.use(bodyParser.raw());
.
如何从POST请求中获取原始字节?
const express = require('express');
const router = express.Router();
/* POST api/img */
router.post('/img', function(req, res, next) {
// how do I …
Run Code Online (Sandbox Code Playgroud) 该JWT.IO网站对创建和验证JSON网络令牌调试器。
当我将我的秘密字符串复制并粘贴到VERIFY SIGNATURE块中时,我可以看到它生成了一个签名。
我向下滚动页面,发现Microsoft实现的.NET解决方案。下载后,我添加了单元测试以手动生成签名。
但是,JWT.IO网站生成的签名与我的单元测试生成的签名略有不同。
Secrect string: "THIS IS A SECRET STRING WHICH CAN BE SHARED BETWEEN THE SERVICES"
Unit test signature: "B0d57pcHoDiTDE/98dyrMx9HoFKGLOcM094eYBgJqHo="
JWT.IO signature: B0d57pcHoDiTDE_98dyrMx9HoFKGLOcM094eYBgJqHo
Run Code Online (Sandbox Code Playgroud)
我注意到JWT.IO签名字符串是URL编码安全的,但是单元测试签名不是。
如何生成与JWT.IO网站相同的签名?
下面被接受的答案使我上了课堂Base64UrlEncoder
。我已经修改了单元测试以生成与JWT.IO网站完全相同的签名:
我正在构建一个使用命名管道与其他进程通信的Windows服务.我对命名管道通信的单元测试是抛出此错误消息4次:
System.AppDomainUnloadedException:尝试访问已卸载的AppDomain.如果测试启动了一个线程但没有停止,则会发生这种情况.确保测试启动的所有线程在完成之前停止.
这是我的单元测试:
[TestMethod]
public void ListenToNamedPipeTest()
{
var watcher = new ManualResetEvent(false);
var svc = new WindowService();
svc.ClientMessageHandler += (connection, message) => watcher.Reset();
svc.ListenToNamedPipe();
sendMessageToNamedPipe("bla");
var wait = watcher.WaitOne(1000);
svc.Dispose();
Assert.IsTrue(wait, "No messages received after 1 seconds");
}
private void sendMessageToNamedPipe(string text)
{
var client = new NamedPipeClient<Message, Message>(DeviceCertificateService.PIPE_NAME);
client.ServerMessage += (conn, message) => Console.WriteLine("Server says: {0}", message.Text);
// Start up the client asynchronously and connect to the specified server pipe.
// This method will return immediately …
Run Code Online (Sandbox Code Playgroud) .net ×2
c# ×2
azure ×1
body-parser ×1
express ×1
jwt ×1
msbuild ×1
msdn ×1
named-pipes ×1
node.js ×1
oauth ×1
powershell ×1
unit-testing ×1