我试图获取rsa.PublicKey的对象,并执行了以下步骤:
----BEGIN RSA PUBLIC KEY----
....
----END RSA PUBLIC KEY----
Run Code Online (Sandbox Code Playgroud)
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
)
func main() {
key, err := ioutil.ReadFile("./new_public.pem")
if err != nil {
fmt.Println(err.Error())
}
block, _ := pem.Decode([]byte(key))
if block == nil {
fmt.Println("unable to decode publicKey to request")
}
pub, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
panic("failed to parse RSA encoded public key" + err.Error())
}
switch pub := pub.(type) {
case *rsa.PublicKey:
fmt.Println("pub is of …Run Code Online (Sandbox Code Playgroud) 我试着在这个表达式中返回True或False,但是我得到了这个错误,有人能告诉我我做错了什么吗?谢谢.
module Main (main) where
import System.IO (stdout, hSetBuffering, BufferMode(NoBuffering))
main::IO()
simOuNao::String -> Bool
main = do hSetBuffering stdout NoBuffering
putStrLn "Guess Number v1.0"
putStrLn "======================"
simOuNao frase = do putStrLn frase
ans <- readLn
if ans == 'y' || ans =='Y'
then return True
else return False
Run Code Online (Sandbox Code Playgroud)
错误信息:
• Couldn't match expected type ‘Bool’ with actual type ‘IO Bool’
• In a stmt of a 'do' block: putStrLn frase
In the expression:
do { putStrLn frase;
ans <- readLn; …Run Code Online (Sandbox Code Playgroud)