简体   繁体   English

Erlang:crypo的问题:sha()

[英]Erlang: Problem with crypo:sha()

This works in my erlang shell: 这适用于我的erlang shell:

1> U = default_user_name().
2> crypto:start().
3> crypto:sha(U).
4> crypto:stop().

But when I compile this: 但是当我编译它时:

default_pw() ->
    U = default_user_name(),
    crypto:start(),
    crypto:sha(U),
    crypto:stop().

And execute it in the erlang shell, I get this: 并在erlang shell中执行它,我得到这个:

1> person:default_pw(). 1> person:default_pw()。

** exception error: bad argument **异常错误:错误的参数

 in function  port_control/3

    called as port_control(crypto_drv04,5,<<"jDoe">>)

 in call from crypto:control/2

Two questions: 两个问题:

1) What am I doing wrong? 1)我做错了什么?

2) It seems that I need to start and stop the crypto server. 2)似乎我需要启动和停止加密服务器。 But is there a better place to start and stop it in my application? 但是在我的应用程序中是否有更好的起点和停止位置?

Many thanks, 非常感谢,

LRP LRP

The error you are getting indicates that the crypto application was not started. 您收到的错误表明加密应用程序未启动。 An easy way to start it is just to add it as a parameter to erl like so: 一个简单的启动方法就是将它作为参数添加到erl如下所示:

$ erl -s crypto

I had a look at the current implementation of crypto and the past release notes for erlang and I came to the following conclusions (someone please correct me if I'm wrong): 我看了一下crypto的当前实现以及针对erlang的过去的发行说明,我得出了以下结论(如果我错了,有人请纠正我):

  1. Erlang releases <14A require crypto to be started prior to calling any functions because the library used a port driver. Erlang发行版<14A要求在调用任何函数之前启动加密,因为库使用了端口驱动程序。 This makes sense because I got the error you described with 13B04 after not starting crypto. 这是有道理的,因为我在没有启动加密后得到了你用13B04描述的错误。
  2. Erlang releases >=14A don't require crypto to be started as the implementation now uses NIFs. Erlang版本> = 14A不需要加密,因为实现现在使用NIF。 This makes sense because the current implementation of crypto_server.erl is just a gen_server template, and on 14B03 I don't need to start the application in order to make crypto:sha/1 work. 这是有道理的,因为crypto_server.erl的当前实现只是gen_server模板,而在14B03我不需要启动应用程序以使crypto:sha/1工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM