如何解决不同的密文使用不同的钠盐库实现?
import java.util.List;
import org.springframework.data.repository.norepositoryBean;
import org.springframework.data.solr.core.solrOperations;
import org.springframework.data.solr.core.query.Criteria;
import org.springframework.data.solr.core.query.SimpleQuery;
import org.springframework.data.solr.repository.support.SimpleSolrRepository;
import org.springframework.stereotype.Repository;
import com.db.Customer360DegreeMetaService.model.solrCustomer;
public class SolrCustomerModelDaoImpl extends SimpleSolrRepository<SolrCustomer,String> implements SolrCustomerModelDao {
// public static void main(String[] args) {
// // Todo Auto-generated method stub
//
// }
public SolrCustomerModelDaoImpl(SolrOperations solrOperations,Class<SolrCustomer> entityClass) {
super(solrOperations,entityClass);
// Todo Auto-generated constructor stub
}
@Override
public List<SolrCustomer> getDetails() {
// Todo Auto-generated method stub
return (List<SolrCustomer>) this.findAll();
}
@Override
public List<SolrCustomer> findByCustomQuery(String searchTerm) {
// Todo Auto-generated method stub
return this.findByCustomQuery(searchTerm);
}
}
`
When I try to Post my SolrDocument Data to my Service Class which has been injected with above Solr
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import javax.transaction.Transactional;
import org.hibernate.annotations.Proxy;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.springframework.data.repository.norepositoryBean;
import org.springframework.data.solr.repository.Query;
import org.springframework.data.solr.repository.solrCrudRepository;
import org.springframework.stereotype.Repository;
import com.db.Customer360DegreeMetaService.model.solrCustomer;
@norepositoryBean
public interface SolrCustomerModelDao extends SolrCrudRepository<SolrCustomer,String> {
@Query(value = "*:*")
List<SolrCustomer> getDetails();
@Query("sysId:*?0* OR firstName:*?0* OR lastName:*?0* OR mobileNo:*?0* OR email:*?0*")
public List<SolrCustomer> findByCustomQuery(String searchTerm);
String columns[] = {"sysId","anId","custCode","name","firstName","lasName","gender","consCustCode","pincode","customerType","mailId","createdUserId","createdDate","updatedUserId","updatedDate" };
}
And I do have an norepositryBean,which is above one,and an implementation of the Repository :
import java.util.List;
import org.springframework.data.repository.norepositoryBean;
import org.springframework.data.solr.core.solrOperations;
import org.springframework.data.solr.core.query.Criteria;
import org.springframework.data.solr.core.query.SimpleQuery;
import org.springframework.data.solr.repository.support.SimpleSolrRepository;
import org.springframework.stereotype.Repository;
import com.db.Customer360DegreeMetaService.model.solrCustomer;
public class SolrCustomerModelDaoImpl extends SimpleSolrRepository<SolrCustomer,entityClass);
// Todo Auto-generated constructor stub
}
@Override
public List<SolrCustomer> getDetails() {
// Todo Auto-generated method stub
return (List<SolrCustomer>) this.findAll();
}
@Override
public List<SolrCustomer> findByCustomQuery(String searchTerm) {
// Todo Auto-generated method stub
return this.findByCustomQuery(searchTerm);
}
I am getting Below exception when trying to Post Solr Documents ;
@SolrDocument(solrCoreName="ganaprimer")
@JsonRootName(value="customer")
public class SolrCustomer extends JSONObject{
@javax.persistence.Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
private String anId;
@Field
private String custCode;
@Field
private String name;
@Field
private String firstName ;
@Field
private String lasName;
@Field
private Character gender;
@Field
private String consCustCode;
@Field
private String pincode;
@Field
private String customerType;
@Field
private String mailId;
@Field
private String createdUserId;
@Field
private Date createdDate;
@Field
private String updatedUserId;
@Field
private Date updatedDate;
I am getting below exception :
2020-09-23 15:54:53 - Completed initialization in 10 ms
org.springframework.dao.DataAccessResourceFailureException: Error from server at http://localhost:8983/solr/ganaprimer: Expected mime type application/octet-stream but got text/html. <html>
<head>
<Meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /solr/ganaprimer/ganaprimer/update. Reason:
<pre> Not Found</pre></p>
</body>
</html>
; nested exception is org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr/ganaprimer: Expected mime type application/octet-stream but got text/html. <html>
<head>
<Meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /solr/ganaprimer/ganaprimer/update. Reason:
<pre> Not Found</pre></p>
</body>
</html>
at org.springframework.data.solr.core.solrExceptionTranslator.translateExceptionIfPossible(SolrExceptionTranslator.java:84)
at org.springframework.data.solr.core.solrTemplate.execute(SolrTemplate.java:169)
at org.springframework.data.solr.core.solrTemplate.saveBean(SolrTemplate.java:221)
at org.springframework.data.solr.repository.support.SimpleSolrRepository.save(SimpleSolrRepository.java:150)
然后,在我的本机应用程序中,我使用react-native-libsodium(Java libsodium-jni的包装器)来生成相同的密码:
$contents = 'Hello World!';
$key = sodium_hex2bin('9fcc21c22142e0cb30e80da941cf1fd2221a3d273b232dac12d0d195d50c0202','');
$nonce = sodium_hex2bin('dd024212d41933c01417bd2aa2b64682224072c8aa1573f3','');
$cipher = sodium_crypto_secretBox($contents,$nonce,$key);
echo bin2hex($cipher);
// output: 0af8d46269eae0788ce4c20569067724402e410b35d9a0c5197be955
我用另外两个JavaScript库sodium-native和sodium-plus测试了该操作。在这两种情况下,结果密文与PHP版本相同。
由于某些原因,我倾向于使用react-native-libsodium,但是一天之后,我找不到为什么该库生成不同的密文以及如何解决该问题。如何生成相同的密文?
解决方法
crypto_secretbox_easy的第三个参数应该是消息的长度,然后是随机数。如此处所示:https://stackoverflow.com/a/23646032/5878961
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。