小编kev*_*ist的帖子

使用libsodium加密

我一直在努力进行加密/使用crypto_secretbox_easy()在解密的一些数据libsodium.我似乎无法找到有关用法的任何好文档.

我想从用户那里获取密码,使用它以某种方式创建密钥,然后使用它来加密/解密数据.

我在下面发布的玩具代码的问题是crypto_secretbox_open_easy()从verify_16.c中返回-1.有没有人知道我在哪里可以找到如何使用这个界面或可能出错的来源?谢谢!

 unsigned char * cipher;
 unsigned char * decoded;
 unsigned char * message;
 unsigned long long message_len = 32;
 size_t noncelen = sizeof(char) * crypto_secretbox_noncebytes();
 size_t keylen = sizeof(char) * crypto_secretbox_keybytes();
 unsigned char * nonce = calloc(noncelen, noncelen);
 unsigned char * key = calloc(keylen, keylen);

 message = calloc(32*sizeof(char), sizeof(char) * 32);
 cipher = calloc(32*sizeof(char), sizeof(char) * 32);
 decoded = calloc(32*sizeof(char), sizeof(char) * 32);

 crypto_secretbox_easy((unsigned char *)cipher, (const unsigned char *)message, 
                      message_len, nonce, key);

 crypto_secretbox_open_easy((unsigned char *)decoded, …
Run Code Online (Sandbox Code Playgroud)

encryption libsodium nacl-cryptography

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

以编程方式使用数据源创建NSCollectionView

我正在尝试NSCollectionView使用a 以编程方式创建NSCollectionViewDataSource.

代码很简单:

self.collectionView = [[NSCollectionView alloc] init];
// Add collection view to self.view etc. 
self.collectionView.dataSource = self;
[self.collectionView registerClass:[NSCollectionViewItem class] forItemWithIdentifier:@"test"]
self.collectionView.collectionViewLayout = gridLayout;
[self.collectionView reloadData]
Run Code Online (Sandbox Code Playgroud)

这导致调用以下方法(如果我没有collectionViewLayout显式设置属性,则这两个方法也不会被调用):

- (NSInteger)numberOfSectionsInCollectionView:(NSCollectionView*)collectionView
- (NSInteger)collectionView:(NSCollectionView*)collectionView numberOfItemsInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)

但是,collectionView:itemForRepresentedObjectAtIndexPath:永远不会被称为.为了确保调用最后一个数据源方法,我还需要做些什么吗?我确保两个计数调用返回> 0,所以这不是问题.

macos cocoa objective-c nscollectionview

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